light: - platform: rflink devices: newkaku_013242b6_2: name: Piano-lamp type: switchable newkaku_013242b5_2: name: Piano-lamp REPEATER type: switchable sensor: - platform: sql db_url: mysql://hassio:hassiopassword@192.168.1.110/RemoteRxLog queries: - name: Piano-lamp repeater status query: "SELECT IF(onOff>0,'on','off') AS status FROM RemoteRxLog.nexaLog where rxTx='R' and remote_id = '20071094' and button='2' order by ts desc LIMIT 1;" column: 'status' input_boolean: piano_light_wanted_state: name: Piano-lamp, wanted state initial: off icon: mdi:lightbulb automation: - alias: Piano-lamp control automation trigger: - platform: template value_template: > {% if state_attr('sensor.piano_lamp_repeater_status', 'status') == states('input_boolean.piano_light_wanted_state') %} false {% else %} true {% endif %} - platform: event event_type: timer.finished event_data: entity_id: timer.piano_lamp_control_timer condition: condition: template value_template: > {% if state_attr('sensor.piano_lamp_repeater_status', 'status') == states('input_boolean.piano_light_wanted_state') %} false {% else %} true {% endif %} action: - service_template: light.turn_{{states('input_boolean.piano_light_wanted_state')}} entity_id: light.piano_lamp_repeater - service_template: > {% if state_attr('sensor.piano_lamp_repeater_status', 'status') == states('input_boolean.piano_light_wanted_state') %} timer.cancel {% else %} timer.start {% endif %} entity_id: timer.piano_lamp_control_timer timer: piano_lamp_control_timer: duration: '00:00:30'