How would you handle this device (2015 Sony TV sleeps after 20 minutes)

Im attempting to bumble together a device type for a 2015 Sony Tv

Ive used some of the posts on here to get together a working script very messy and just basic buttons for control

so far i can put the tv into standbye and turn it on again, select inputs and send some remote commands, I can also poll the tv for status, “active” “standby”

the problem with the TV is after 20 mins or so of being in standby the tv goes to sleep, and it no longer responds to any command over the network (at least on wifi). If i poll it i dont get any response and i can’t bring it out of standby. I can however send a smart things WOL packet which wakes it up and turns the tv on again. this brings it out of standby so no use for polling as the Tv would turn on every 5 mins

i need to figure out a way of coding, it to say if you get no response from polling the TV set the TV as off, and when the ST on off switch is pressed send the wake on lan packet instead of the wake from standbye command (annoyingly although the WOL packet turns the tv on (the screen comes on), it doesnt bring it out of standby(screen stays off if in standby already) or i could just use that every time)

additional to this, this is the response to one of the polls of the TV

‘[index:17, mac:ACD1B83DDA7B, ip:C0A8000C, port:0050, requestId:bd6a4d7f-8886-4896-99db-ab970f0715ba, headers:[content-length:40, http/1.1 200 ok:null, connection:keep-alive, content-type:application/json, date:Tue, 22 Nov 2016 10:20:08 GMT], body:{“id”:2,“result”:[{“status”:“standby”}]}, header:HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 40
Connection: keep-alive
Date: Tue, 22 Nov 2016 10:20:08 GMT, status:200, data:[id:2, result:[[status:standby]]], json:[id:2, result:[[status:standby]]]]’

id like to parse this message for the Mac address, that way should someone want to use it for their TV they wont have to find it out, it will self populate

currently i parse it for status (standby like this)

def poll() {
log.debug "Executing ‘poll’"
def json = "{“id”:2,“method”:“getPowerStatus”,“version”:“1.0”,“params”:[]}"
def result = sendJsonRpcCommand(json)
}

def parse(description) {

def msg = parseLanMessage(description)
if (msg.json?.id == 2) {
def status = (msg.json.result[0]?.status == “active”) ? “on” : "off"
sendEvent(name: “switch”, value: status)
log.debug “TV is ‘${status}’”
}
}

any help would be great. thanks

hmm strange the WOL command seemed to work once and now wont work at all

does it look correct to you guys assuming that is the correct mac address?

def WOLC() {

def result = new physicalgraph.device.HubAction (
    "ACD1B83DDA7B", 
    physicalgraph.device.Protocol.LAN,
    null,
    [secureCode: "111122223333"]
)
return result

}

ok with some help i figured out the WOL command should be as follows

def result = new physicalgraph.device.HubAction (
“wake on lan ACD1B83DDA7B”,
physicalgraph.device.Protocol.LAN,
null,
[secureCode: “111122223333”]
)
return result

the problem i see is that when using local hubaction you are sending the command and that’s effectively it, the parse then reads the reply which is a separate function to parses the response however you want to feedback to the power on function that there is no response. this would effectively lock that thread whilst waiting for the response its just not something that ST can do.

if you have a WRT based router that supports JFFS you could look for the MAC address being active, thats what i do to track if my Smart TV’s are connected to my network, its quick and reliable and you could then have a virtual switch that is on or off dependant on if the TV is active on your network and do things dependant on the status of the virtual switch. i use that to detect if a room is occupied.
see my post on AsusWrt for more info

although that may be over complicating things, why don’t you just send the WOL and then the On command for good measure with a delay needed between each command when you choose to turn the TV on. it may well delay the switch-on by a couple of seconds, but that wouldn’t matter too much would it? that way there would be no detection needed. the ST hub doesn’t do ping tests etc. without an external device

1 Like

yeah im thinking about doing something like that. i wonder if i can set something

thinking outloud, could i set a variable in some way so poll the tv and set a variable to 0 if a response comes back set it to 1

that way i know the tv is responding, if it stops responding the variable will be 0 and i can do actions based on that. there may be the odd time where there are crossed wires but it shouldn’t really effect anything.

id like the device handler to be self contained and that way easy for other users to set up as im pretty sure all 2015 and 2016 smart sony tvs should work with it, it would be a shame to have a load of code in it that only works if you have the correct router or whatever
whilst the function may be better with external stuff, it would be frustrating for other users trying to set it up

I assume it would be best if every time i Poll for a status i first reset the varialble holidng the json response from the last poll to either null or 0 or something anyway?

problem im having at the moment is if there is no response and the tv’s last status poll replied active, it continues to think it is active, because no response comes back to overwrite the previous response

oh also i figured out how to parse the reponse for the mac address it was as simple as msg.mac

next on the list is to see if i can populate the smarthings network ID automatically

I would just remove eco-power saving/ thing on Sony. They have it defaulted enabled to hit their Energy Star requirements.

if that sorts it out it might be worth it, save me all the arsing around

[Settings] > [TV] > [Power] and it should be around there.