Skip to content
Snippets Groups Projects
Select Git revision
  • 21929857e59c8fe48a495cdc1b6cd7dcbc873c3c
  • main default protected
  • growscreen
3 results

light.yaml

Blame
  • light.yaml 1.52 KiB
    substitutions:
      # Schedules
      #schedule_grow_on: "0 0 3 * * *"
      #schedule_grow_off: "0 0 21 * * *"
      #schedule_bloom_on: "0 0 6 * * *"
      #schedule_bloom_off: "0 0 18 * * *"
      schedule_grow_on: "5,15,25,35,45,55 * * * * *"
      schedule_grow_off: "0,10,20,30,40,50 * * * * *"
      schedule_bloom_on: "0 * * * * *"
      schedule_bloom_off: "30 * * * * *"
    
    prometheus:
      relabel:
        propbox_light:
          id: light
          name: Light
    
    sensor:
      - platform: template
        name: "schedule"
        lambda: return id(schedule).active_index();
        internal: true
    
    select:
      - platform: template
        id: schedule
        name: "Light: Schedule"
        options: ["Disabled", "Grow", "Bloom"]
        initial_option: "Disabled"
        optimistic: true
        restore_value: true
    
    switch:
      - platform: template
        id: propbox_light
        name: "Status: Light"
        optimistic: true
        turn_on_action:
          - http_request.post: http://${hostname_light}/switch/power/turn_on
        turn_off_action:
          - http_request.post: http://${hostname_light}/switch/power/turn_off
    
    interval:
      - interval: 1min
        then:
          - script.execute: light_state
    
    script:
      - id: light_state
        then:
          - lambda: |-
              HTTPClient http;
              bool state = false;
              http.begin("http://${hostname_light}/switch/power");
              if (http.GET() == 200) {
                  DynamicJsonDocument doc(200);
                  deserializeJson(doc, http.getString());
                  state = (doc["state"] == "ON") ? true : false;
              }
              id(propbox_light).publish_state(state);
              http.end();