Преглед изворни кода

Moved ext light auto to python.

Thomas Chef пре 4 година
родитељ
комит
d425ff7d9b
2 измењених фајлова са 23 додато и 73 уклоњено
  1. 1 73
      packages/ext_lights_automation.yaml
  2. 22 0
      pyscript/ext_light_control.py

+ 1 - 73
packages/ext_lights_automation.yaml

@@ -4,76 +4,4 @@ input_boolean:
     name: Exterior lights, wanted state
     icon: mdi:lightbulb
 
-  ext_light_on_done:
-    name: Bool switch, Ext light turned ON
-    icon: mdi:car
-  ext_light_off_done:
-    name: Bool switch, Ext light turned OFF
-    icon: mdi:car
-
-automation:
-  - alias: Exterior lights ON in evening
-    description: In the evening, turn the lights ON
-    trigger:
-    - platform: numeric_state
-      entity_id: sensor.lux_outside_the_garage
-      below: 100
-    condition:
-      condition: and
-      conditions:
-        - condition: state
-          entity_id: input_boolean.ext_light_on_done
-          state: 'off'
-        - condition: state
-          entity_id: input_boolean.exterior_lights_wanted_state
-          state: 'off'
-    action:
-    - service: input_boolean.turn_on
-      data: {}
-      entity_id: input_boolean.exterior_lights_wanted_state
-    - service: input_boolean.turn_on
-      data: {}
-      entity_id: input_boolean.ext_light_on_done
-    mode: single
-
-
-  - alias: Exterior lights OFF in morning
-    description: ''
-    trigger:
-    - platform: numeric_state
-      entity_id: sensor.lux_outside_the_garage
-      above: 50
-    condition:
-      condition: and
-      conditions:
-        - condition: state
-          entity_id: input_boolean.ext_light_off_done
-          state: 'off'
-        - condition: state
-          entity_id: light.exterior_lights
-          state: 'on'
-    action:
-    - service: input_boolean.turn_off
-      data: {}
-      entity_id: input_boolean.exterior_lights_wanted_state
-    - service: input_boolean.turn_on
-      data: {}
-      entity_id: input_boolean.ext_light_off_done
-    mode: single
-
-
-
-  - alias: Turn boolean switches off at midnight
-    description: ''
-    trigger:
-    - platform: time
-      at: 00:05:00
-    condition: []
-    action:
-    - service: input_boolean.turn_off
-      data: {}
-      entity_id: input_boolean.ext_light_off_done
-    - service: input_boolean.turn_off
-      data: {}
-      entity_id: input_boolean.ext_light_on_done
-    mode: single
+  

+ 22 - 0
pyscript/ext_light_control.py

@@ -0,0 +1,22 @@
+
+state.persist('pyscript.ext_light_on_done','off')
+state.persist('pyscript.ext_light_off_done','off')
+
+@time_trigger("once(00:15:00)")
+def reset_ext_light_done_states():
+    log.info(f"Reset the ext light done state variables.")
+    pyscript.ext_light_on_done = 'off'
+    pyscript.ext_light_off_done = 'off'
+
+@state_trigger( "int(sensor.lux_outside_the_garage) < 100 and int(sensor.lux_outside_the_garage.old) >= 100")
+def automate_exterior_lights_on_in_evening():
+    if pyscript.ext_light_on_done == 'off' and input_boolean.exterior_lights_wanted_state == 'off':
+        input_boolean.exterior_lights_wanted_state = 'on'
+        pyscript.ext_light_on_done = 'on'
+
+@state_trigger( "int(sensor.lux_outside_the_garage) > 50 and int(sensor.lux_outside_the_garage.old) <= 50")
+def automate_exterior_lights_off_in_morning():
+    if pyscript.ext_light_off_done == 'off' and input_boolean.exterior_lights_wanted_state == 'on':
+        input_boolean.exterior_lights_wanted_state = 'off'
+        pyscript.ext_light_off_done = 'on'
+