triggeringItem
only exists in the DSL, but scripted automation has event.itemName, event.itemState, etc… But How Do I…? — openHAB Helper Libraries documentation.
Don’t trigger the rule when the group is updated (groups don’t receive updates)… use a “Member of” trigger instead. I also combined both rules into one…
from core.rules import rule
from core.triggers import when
@rule("Turn ON/OFF the home cinema", description="Turn ON/OFF the home cinema", tags=["home_cinema"])
@when("Member of Home_Cinema received update")
def turn_on_off_cinema(event):
if isinstance(items[event.itemName], UnDefType): # stop the rule if the state is NULL or UNDEF
return
turn_on_off_cinema.log.info("Turned {} home cinema".format(event.itemState))
sendCommandCheckFirst("projector_screen", event.itemState.toString())
if event.itemState == ON:
sendCommandCheckFirst("denon_x3500h_power", "ON")
elif event.itemState == OFF:
avr_state = getItemValue("denon_x3500h_input","ERROR")
if avr_state == "ERROR":
turn_off.log.error("denon_x3500h_input: could not get item value.")
elif avr_state == "MPLAY" or avr_state == "GAME":
sendCommandCheckFirst("denon_x3500h_power","OFF")
else:
turn_off.log.info("getItemValue('denon_x3500h_input') != 'MPLAY': Not turning off 'denon_x3500h_power'")
if event.itemName == "pChromecast_Livingroom_Active":
sendCommandCheckFirst("denon_x3500h_input", "MPLAY")
elif event.itemName == "HTPC":
sendCommandCheckFirst("denon_x3500h_input", "GAME")