123456789101112131415161718192021222324252627282930313233343536373839404142 |
- from homeassistant.const import EVENT_STATE_CHANGED
- # This script reacts to the actual sensor on the door
- # It sets the input_boolean which keeps its state during restarts
- # Arguments could be: (entity_id=None, new_state=None, old_state=None):
- @event_trigger(EVENT_STATE_CHANGED, "entity_id=='binary_sensor.bedroom_door_raw_sensor'")
- def bedroom_door_raw_sensor():
- #log.info(f"monitor_bedroom_door_event: entity {entity_id} changed from {old_state} to {new_state}")
- log.info(f"********* BEDROOM RAW SENSOR: "+binary_sensor.bedroom_door_raw_sensor+" ***********")
- input_boolean.bedroom_door = binary_sensor.bedroom_door_raw_sensor
- pyscript.handle_bedroom_light()
- # This service handles the window light in the bedroom
- # It reacts when the door opens/closes or when a state_goto-script is run
- # when someone has pressed a button on the wall or kitchen IPhone.
- @service
- def handle_bedroom_light():
- task.unique('handle_bedroom_light')
- log.info(f"********* BEDROOM LIGHT CONTROL **** Btn_4:" + light.main_button_4 + " Door:"+ input_boolean.bedroom_door)
- task.sleep(1)
- # The door sensor is out of battery, and thats why I disable this for now
- #if light.main_button_4 == 'on' and input_boolean.bedroom_door == 'on':
- if light.main_button_4 == 'on':
- # If OPEN
- switch.turn_on(entity_id='switch.tradfri_outlet')
- else:
- switch.turn_off(entity_id='switch.tradfri_outlet')
- """
- # This way does not work, beacuse it does not react to "off" when the door is already "off/aka Unknown" after a restart of HA
- @state_trigger("binary_sensor.bedroom_door_raw_sensor")
- def bedroom_door_raw_sensor():
- log.info(f"********* BEDROOM RAW SENSOR: "+binary_sensor.bedroom_door_raw_sensor+" ***********")
- input_boolean.bedroom_door = binary_sensor.bedroom_door_raw_sensor
- pyscript.handle_bedroom_light()
- """
|