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

light_power.yaml

Blame
  • light_power.yaml 989 B
    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"
              on_response:
                then:
                  - lambda: |-
                      json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
                        id(power_light).publish_state(root["value"]);
                      });
    
    prometheus:
      relabel:
        power_light:
          id: power_light
          name: "Power Light"