Patryk M. Gutowski 1 год назад
Родитель
Сommit
24d4d9d443
1 измененных файлов с 58 добавлено и 50 удалено
  1. 58 50
      ff-akwarium-plug-01.yaml

+ 58 - 50
ff-akwarium-plug-01.yaml

@@ -74,22 +74,30 @@ binary_sensor:
   - platform: status
     name: Status
     entity_category: diagnostic
-
   - platform: gpio
     pin:
       number: P7
+      inverted: true
       mode:
         input: true
         pullup: true
-      inverted: true
     name: "Power Button"
     on_press:
-      - switch.toggle: relay
+      # - output.toggle: relay
       - select.next:
-          id: mode
+          id: light_mode
           cycle: true
 
-switch:
+light:
+  - platform: binary
+    name: Red LED
+    id: red_led
+    output: led_1
+    internal: True
+    restore_mode: ALWAYS_OFF   
+
+
+output:
   - platform: gpio
     # RED
     id: led_1
@@ -97,27 +105,13 @@ switch:
       number: P6
       inverted: false
 
-  - platform: gpio
-    # BLUE
-    id: led_2
-    pin:
-      number: P26
-      inverted: false
-
-  - platform: gpio
-    pin: P8
-    id: relay
-    internal: true 
-    
-    # Turn off red LED to show blue when turned on
-    on_turn_on:
-      - switch.turn_on: led_2
-      - switch.turn_off: led_1
-
-    # Turns on the red LED once the plug is turned off
-    on_turn_off:
-      - switch.turn_off: led_2
-      - switch.turn_on: led_1
+#  - platform: gpio
+#    # BLUE
+#    id: led_2
+status_led:
+  pin:
+    number: P26
+    inverted: false
 
 button:
   - platform: restart
@@ -125,35 +119,33 @@ button:
     name: Restart
     entity_category: diagnostic  
 
-
 globals:
- - id: current_light
-   type: select
-   restore_value: True
-   initial_value: "0"
+  - id: current_light
+    type: int
+    initial_value: "0"
 
 select:
   - platform: template
     name: "Light Mode"
-    id: mode
+    id: light_mode
     options:
      - "Off"
      - "Day"
-     - Daybreak
-     - Night
+     - "Daybreak"
+     - "Night"
     optimistic: true
     on_value:
       then:
         - if:
             condition:
               - lambda: |-
-                  return(id(mode).state) == "Off";
+                  return(id(light_mode).state) == "Off";
             then:
               - switch.turn_off: relay
         - if:
             condition:
               - lambda: |-
-                  return(id(mode).state) == "Day";
+                  return(id(light_mode).state) == "Day";
             then:
               - switch.turn_off: relay
               - delay: 20s
@@ -161,7 +153,7 @@ select:
         - if:
             condition:
               - lambda: |-
-                  return(id(mode).state) == "Daybreak";
+                  return(id(light_mode).state) == "Daybreak";
             then:
               - switch.turn_off: relay    
               - delay: 20s
@@ -174,7 +166,7 @@ select:
         - if:
             condition:
               - lambda: |-
-                  return(id(mode).state) == "Night";
+                  return(id(light_mode).state) == "Night";
             then:
               - switch.turn_off: relay    
               - delay: 20s
@@ -186,16 +178,32 @@ select:
               - switch.turn_off: relay
               - delay: 200ms
               - switch.turn_on: relay
+        - lambda: |- 
+            id(current_light) == id(light_mode).active_index();
 
-light:
-  - platform: template
-    name: None
-    restore_mode: RESTORE_AND_OFF
-    effects:
-      - lambda:
-          name: Day
-      - lambda:
-          name: Daybreak
-      - lambda:
-          name: Night
-              
+switch:
+  - platform: gpio
+    pin: P8
+    id: relay
+    internal: true
+    restore_mode: ALWAYS_OFF   
+    # Turn off red LED to show blue when turned on
+    on_turn_on:
+     - light.turn_on: red_led
+    #  - switch.turn_off: led_1
+    # Turns on the red LED once the plug is turned off
+    on_turn_off:
+      - light.turn_off: red_led
+    #  - switch.turn_on: led_1
+#  - platform: template
+#    name: mode
+#    output: relay
+#    internal: True
+#    effects:
+#      - lambda:
+#          name: Day
+#      - lambda:
+#          name: Daybreak
+#      - lambda:
+#          name: Night
+