upfront apology: I’ve been doing a lot of openhab configs last few days (with frustration and yet successes) and I’m stuck on getting some states to sync without unwanted side-effects. I normally do a lot of reading first before posting and have done for this issue but I think I’m just overloaded with what I’ve read and I hope a direct plea for help will get me over this particular bump.
I have a Samsung TV and a Broadlink RM2 and use the following bindings:
Samsung binding for general Samsung TV stuff
Broadlink binding for sending IR code to TV
Network binding for online status
My .items
Switch LRTV_online "LR TV online" { channel="network:pingdevice:192_168_2_96:online"}
Switch LRTVpower "LR TV" { channel="samsungtv:tv:accd7816_e74e_4cd5_a147_f5173316f64b:power"}
Switch LRTVpowerRM2 "LR TV Power (RM2)"
String BroadlinkRM2 "BroadlinkRM2" { channel="broadlink:rm2:b4-43-0d-da-25-b2:command"}
My .sitemap
Text item=LRTVpower label="LR TV is [%s ]" icon=television //Displays TV state. ping could be used but Samsung binding is faster.
Switch item=LRTVpower //Uses Samsung binding
Switch item=LRTVpowerRM2 //Virtual switch which uses rules to send IR power command via RM2
My .rules
rule "LRTV power"
when
Item LRTVpowerRM2 changed
then
if (LRTVpowerRM2.state == ON)
{
BroadlinkRM2.sendCommand("LRTVpower")
}else if (LRTVpowerRM2.state == OFF)
{
BroadlinkRM2.sendCommand("LRTVpower")
}
end
The Samsung binding (and related switch) can switch my TV off but not on, but knows TV state so is ON when TV is on and off when TV is off no matter how the TV was put into the state.
The LRTVpowerRM2 switch sends an IR code and can be used to switch the TV on or off.
What I’d like to have is the LRTVpowerRM2 switch change how it looks in the UI depending if the TV is on or off (and so depending either if LRTV_online is ON/OFF but preferably if LRTVpower is ON/OFF) because this way it is always ready to propose the right action even if the physical remote is used, or the Samsungbinding is used to switch the TV off.
I tried to create a rule for this ‘sync’ and tried several variations which didn’t work.
I currently have:
rule "Sync RM2 IR LRTV Power switch with TV state"
when
Item LRTVpower received command
then
LRTVpowerRM2.postUpdate(LRTVpower.state)
end
and although this does change the RM2 switch state it also sends the command so I get either a TV switch on (physical remote) and then a TV switch off follows (via RM2 switch automatically), or the TV is switched off (Samsung binding or physical remote) and then gets switched on (via the RM2 switch).
I had thought about using the item autoupdate=false parameter but not sure of the ramifications in this scenario and can’t check it now as kids and wife have the TV.
I did also find this rule/trigger table https://docs.openhab.org/configuration/rules-dsl.html#manipulating-item-states but at this stage my brain isn’t able to process.
I hope what I provide is clear enough and someone is able to offer some help. Thanks in advance.