Pārlūkot izejas kodu

Ext lights working with new control.

Thomas Chef 4 gadi atpakaļ
vecāks
revīzija
0f10e77bfe

+ 0 - 3
configuration.yaml

@@ -61,9 +61,6 @@ sensor:
         query: "SELECT CAST(AVG(data) AS signed) as data FROM (SELECT data FROM RemoteRxLog.rawTemp WHERE type = 'lux' and data < '65535' ORDER BY id DESC LIMIT 3) items;"
         column: 'data'
         unit_of_measurement: Lux
-      - name: Exterior light status
-        query: "SELECT onOff FROM RemoteRxLog.nexaLog where rxTx='R' and remote_id = '20071094' and button='1' order by ts desc LIMIT 1;"
-        column: 'onOff'
       - name: Outside temperature
         query: "SELECT temp1 FROM RemoteRxLog.temp order by ts desc LIMIT 1;"
         column: 'temp1'

+ 10 - 28
packages/ext_lights.yaml

@@ -1,24 +1,12 @@
-############################ Battery Automations, Scripts & Sensors ##################################
-# All entities to have the prefix: "battery_" or name: Battery: 
-######################################################################################################
-
-
-light:
-  - platform: rflink
-    automatic_add: true
-    devices:
-      newkaku_013242b6_1:
-        name: Exterior lights
-        type: switchable
-      newkaku_013242b5_1:
-        name: Exterior lights REPEATER
-        type: switchable
 
 input_boolean:
+  exterior_lights_wanted_state:
+    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
@@ -37,15 +25,12 @@ automation:
           entity_id: input_boolean.ext_light_on_done
           state: 'off'
         - condition: state
-          entity_id: light.exterior_lights
+          entity_id: input_boolean.exterior_lights_wanted_state
           state: 'off'
     action:
-    - service: light.turn_on
-      data: {}
-      entity_id: light.exterior_lights_repeater
-    - service: light.turn_on
+    - service: input_boolean.turn_on
       data: {}
-      entity_id: light.exterior_lights
+      entity_id: input_boolean.exterior_lights_wanted_state
     - service: input_boolean.turn_on
       data: {}
       entity_id: input_boolean.ext_light_on_done
@@ -68,12 +53,9 @@ automation:
           entity_id: light.exterior_lights
           state: 'on'
     action:
-    - service: light.turn_off
-      data: {}
-      entity_id: light.exterior_lights_repeater
-    - service: light.turn_off
+    - service: input_boolean.turn_off
       data: {}
-      entity_id: light.exterior_lights
+      entity_id: input_boolean.exterior_lights_wanted_state
     - service: input_boolean.turn_on
       data: {}
       entity_id: input_boolean.ext_light_off_done
@@ -94,4 +76,4 @@ automation:
     - service: input_boolean.turn_off
       data: {}
       entity_id: input_boolean.ext_light_on_done
-    mode: single
+    mode: single

+ 58 - 0
packages/ext_lights_control.yaml

@@ -0,0 +1,58 @@
+
+
+
+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'
+

+ 5 - 7
packages/test_stuff.yaml

@@ -27,13 +27,8 @@ input_boolean:
 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: state
+      entity_id: input_boolean.piano_light_wanted_state
     - platform: event
       event_type: timer.finished
       event_data:
@@ -49,6 +44,8 @@ automation:
     action:
     - service_template: light.turn_{{states('input_boolean.piano_light_wanted_state')}}
       entity_id: light.piano_lamp_repeater
+    - service_template: light.turn_{{states('input_boolean.piano_light_wanted_state')}}
+      entity_id: light.piano_lamp
 
     - service_template: >
         {% if state_attr('sensor.piano_lamp_repeater_status', 'status') == states('input_boolean.piano_light_wanted_state') %}
@@ -57,6 +54,7 @@ automation:
           timer.start
         {% endif %}
       entity_id: timer.piano_lamp_control_timer
+    mode: single
 
 
 timer: