Hi,
is there a way to change the state of a switch and prevent the events that would normaly be triggered…
The problem:
I have a virtual switch for “Media”… If changed to ON it triggers the main switch (Fritz socket) dimms the light, switches on TV, speakers and FireTV etc. and does the opposite stuff on OFF switch.
So if I switch on the Fritz socket manually I want to set the OH media switch set to ON as well, but without triggering the events, because most of that stuff is triggered by IR via harmony so I have no way of recognizing if the TV is already on or off.
So if I’d make a rule that checks the Fritz socket and sets the “Media” to ON if the socket is on (so that that the switch has the correct state), it would start the normal Media rule routine… that again sends a the PowerToggle to the TV that would switch it off…
I think what you need is to use “received command” to trigger your rules that execute when Media is commanded and the lights and TV and everything else needs to be turned ON or OFF or adjusted.
Then the rule that checks the state to see if the Media should be ON but isn’t already, use postUpdate. postUpdate will change the state of your Media switch and because your Rule only triggers on commands, the Rule will not be triggered.
This is the virtual switch (no binding) that triggers the whole Media foo:
rule "Media"
when
item mediaSWT changed from OFF to ON
then
sendCommand(fritzSWT, ON) // <-- switches on my socket
//other stuff...
sendCommand(harmnonyTvSWT, 'Powertoggle') // <-- switches on my TV
//other stuff...
end
If someone switches on the media on (rule “Media”), the switch will be ON afterwards.
But if if someone switches on the socket without OH the media will go on, but the media switch item will still be OFF and we have an inconsistent state.
So I want something like this, to adapt change the switch accordingly
rule "Manual"
when
item harmnonyTvSWT changed from OFF to ON
then
sendCommand(mediaSWT, ON) // <-- this I want to do without triggering the "Media" rule above
end
BUT: If I do this, the normal “media” rule is triggert again, in terms of the switch this is has no effect (it gets the “ON” command again, and nothing will happen). The problem is the TV, that will get a “PowerToggle” again and will switch OFF…
I’ll assume the “item” is a typo. It needs to be “Item”.
OK, so this will trigger the rule anytime mediaSWT changed from OFF to ON for any reason. This won’t work for you. You will need to change the trigger and Rule to:
rule "Media"
when
Item mediaSWT received command
then
if(receivedCommand == ON) {
fritzSWT.sendCommand(ON)
// other stuff
harmonyTvSWT.sendCommand('Powertoggle')
// other stuff
}
else {
// stuff to do when mediaSWT receives command OFF
}
end
rule "Manual"
when
Item harmonyTvSWT changed from OFF to ON
then
mediaSWT.postUpdate(ON)
end
With this configuration, the Manual Rule will not trigger the Media Rule when it updates the mediaSWT to ON. But when you toggle the switch from your Sitemap or from a rule using mediaSWT.sendCommand(ON) the “Media” rule will trigger.