ext_lights_control.yaml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. light:
  2. - platform: rflink
  3. automatic_add: true
  4. devices:
  5. newkaku_013242b6_1:
  6. name: Exterior lights
  7. type: switchable
  8. newkaku_013242b5_1:
  9. name: Exterior lights REPEATER
  10. type: switchable
  11. sensor:
  12. - platform: sql
  13. db_url: mysql://hassio:hassiopassword@192.168.1.110/RemoteRxLog
  14. queries:
  15. - name: Exterior light status
  16. 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;"
  17. column: 'status'
  18. automation:
  19. - alias: External light control
  20. trigger:
  21. - platform: state
  22. entity_id: input_boolean.exterior_lights_wanted_state
  23. - platform: event
  24. event_type: timer.finished
  25. event_data:
  26. entity_id: timer.ext_light_control_timer
  27. condition:
  28. condition: template
  29. value_template: >
  30. {% if state_attr('sensor.exterior_light_status', 'status') == states('input_boolean.exterior_lights_wanted_state') %}
  31. false
  32. {% else %}
  33. true
  34. {% endif %}
  35. action:
  36. - service_template: light.turn_{{states('input_boolean.exterior_lights_wanted_state')}}
  37. entity_id: light.exterior_lights_repeater
  38. - service_template: light.turn_{{states('input_boolean.exterior_lights_wanted_state')}}
  39. entity_id: light.exterior_lights
  40. - service_template: >
  41. {% if state_attr('sensor.exterior_light_status', 'status') == states('input_boolean.exterior_lights_wanted_state') %}
  42. timer.cancel
  43. {% else %}
  44. timer.start
  45. {% endif %}
  46. entity_id: timer.ext_light_control_timer
  47. mode: single
  48. timer:
  49. ext_light_control_timer:
  50. duration: '00:00:45'