light: - platform: rflink automatic_add: true devices: newkaku_013242b6_1: name: Exterior lights type: switchable newkaku_013242b5_1: name: Exterior lights REPEATER type: switchable sensor: - platform: sql db_url: mysql://hassio:hassiopassword@192.168.1.110/RemoteRxLog queries: - name: Exterior light status query: "SELECT IF(onOff>0,'on','off') AS status FROM RemoteRxLog.nexaLog where rxTx='R' and remote_id = '20071094' and button='1' order by ts desc LIMIT 1;" column: 'status' automation: - alias: External light control trigger: - platform: state entity_id: input_boolean.exterior_lights_wanted_state - platform: event event_type: timer.finished event_data: entity_id: timer.ext_light_control_timer condition: condition: template value_template: > {% if state_attr('sensor.exterior_light_status', 'status') == states('input_boolean.exterior_lights_wanted_state') %} false {% else %} true {% endif %} action: - service_template: light.turn_{{states('input_boolean.exterior_lights_wanted_state')}} entity_id: light.exterior_lights_repeater - service_template: light.turn_{{states('input_boolean.exterior_lights_wanted_state')}} entity_id: light.exterior_lights - service_template: > {% if state_attr('sensor.exterior_light_status', 'status') == states('input_boolean.exterior_lights_wanted_state') %} timer.cancel {% else %} timer.start {% endif %} entity_id: timer.ext_light_control_timer mode: single timer: ext_light_control_timer: duration: '00:00:45'