Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

light_power.yaml

Blame
  • light_power.yaml 1.07 KiB
    esphome:
      on_boot:
        priority: -200
        then:
          - wait_until:
              wifi.connected:
          - lambda: |-
              id(light_power_state).execute();
    
    switch:
      - platform: template
        id: power_light
        name: "Light: Power"
        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_power_state
    
    script:
      - id: light_power_state
        then:
          - http_request.get:
              url: "http://${hostname_light}/switch/power"
              headers:
                Content-Type: application/json
              capture_response: true
              on_response:
                then:
                  - lambda: |-
                      json::parse_json(body, [](JsonObject root) -> bool {
                        id(power_light).publish_state(root["value"]);
                        return true;
                      });
    
    prometheus:
      relabel:
        power_light:
          id: power_light
          name: "Power Light"