1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 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):
- #
- # TypeError: bedroom_door_raw_sensor() called with unexpected keyword arguments: entity_id, new_state, old_state
- #
- @event_trigger(EVENT_STATE_CHANGED, "entity_id=='binary_sensor.bedroom_door_raw_sensor'")
- def bedroom_door_raw_sensor(entity_id, new_state, old_state):
- #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)
- # Select which line to used based on if there is power in the door sensor battery
- if light.main_button_4 == 'on' and input_boolean.bedroom_door == 'on':
- #if light.main_button_4 == 'on': # Use if battery is out of power
- # 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()
- """
|