Sony Bravia TV Driver - Triggering - Event vs State

I've recently installed the Sony Bravia Community Driver It works well and I can trigger different remote commands via Hubitat.

Ultimately what I'm trying to do is to set a Scene of lights when I turn my TV on. I've set up the following rule.

This works sometimes... I believe the issue is regarding the issue of Event vs State. I understand that this driver polls the TV every 60 seconds. Because of this, I realize that the lights will not change instantly but I want them to change at that next polling within the upcoming minute. My rule is trying to use an event as a trigger but because it doesn't send this signal automatically it misses the event and only sees that the state has changed to "ON".

I guess my real question is why does it work sometimes? I wouldn't have been surprised if it didn't work because of the Event vs State issue but the fact that it's inconsistent is puzzling.

Any suggestions?

That driver uses soap calls to poll for state. I wrote one that calls the rest API instead. I have a major update to make that will check capabilties of tv and unlock functions if available. Just had a baby and started remodel, so it might be awhile, but it should still work better than to soap call one.

The Rest API driver rocks. It's good! Thank you for this.

Hello @ajones, I'm still very new to all of this, and I'm looking to import your driver to eventually make a rule that says if tv is on then turn on x. Can you please link me to the latest version on GitHub for the code? In the article you posted it looks like you have made several updates and I want to make sure I use the latest release. Thank you!

Edit, I used the driver from the import url and looks to be working. Im not getting all information in my state variables but I can turn the TV on and off and see that state which is all I wanted from the driver. Thank you so much. I am using xbr-55x900e tv

I'm doing something similar with my Living Room lights if the TV is turned on or off.

Maybe my experience will assist because I noted that the on/off is a state which gets checked as often as the driver polls the TV. So if you set up a rule that has a trigger for on or off, it will be activated every minute (at least it does in my setup) The terminology in the Rule Machine trigger is misleading. Your rule will not be triggered when the TV switch "becomes" on or off at all. It will be triggered when the state of the TV is checked (every minute) and found to be on or off. Hence your rule will continuously retrigger. So get ready to use the Private Boolean or other method to only run the rule the first time the state really gets changed.

In case it helps, here's an example rule I've found to be effective...

1 Like

Thank you so much for the heads up @Angus_M! I'm looking for something exactly like what you did. Basically I want, if tv is on, turn lights on. If tv is off, turn lights off. I am the opposite of a coder, and can only kinda see what your example rule does. Any chance you can send me a screenshot of my simple rule with one of your lights? I would really appreciate it!

Yeah, my rule does a few things so is a bit complicated.

The idea of using a PB is to avoid the rule re-running all the time when the TV is polled and the state is read again. Actually it doesn't really matter if you are just turning the lights on and off. The hub will just send the command to turn the lights on and off and whatever state they are in there is no harm done. If they are already on and the hub asks them to go on again, it doesn't matter actually.

So you could simply have 2 simple rules like...

Trigger - TV becomes On
Actions - Living Room Lights Off

Trigger - TV becomes Off
If mode is Evening or Night (
Living Room Lights On
)

If you did want to avoid doing actions that are not needed and rill it all into a single rule, then you'd need something like this...

Trigger - if TV changed

Actions

If TV is On (
If Private Boolean is True (
Private Boolean False
Lights Off
)
) else (
If Private Boolean is False (
Private Boolean True
If Mode is Evening or Night (
Lights On
)
)
)

Sometimes with a rule like this the PB can get out of phase, so you can just toggle the TV on wait a minute, then off and wait a minute and then it should resequence the PB in line with the state of the TV on/off. Alternatively in the next release I believe the PB will get set to True when a rule is stopped. So then restart the rule and you then will know the PB is set to True. I think they also get set to True when the hub reboots. Alternatively you can use a variable instead of a PB which makes its state more visible.

Hope it helps. Give it a try and learn!

Thank you so much! I have a lot to learn but thankfully what I'm trying to do isn't that complicated. I really appreciate the help!

Edit:

So I decided to let the rule run every minute as it doesn't harm anything. I couldn't figure our Rule Machine, but I got everything working on Basic Rules.

When Living Room TV turns on ...
Turn on Living Room TV Backlight
Wait until Living Room TV turns off, then ...
Turn off Living Room TV Backlight

What this does is that it turns on my LED TV Backlight strip when the TV goes on, and turns it off when the TV goes off. Thank you for your help!

1 Like