Automation of light based on pirateweather temp

I am trying to get an automation to turn on a light in the well house based on current temperature. Can you tell me what is wrong with the following?

alias: Well Lamp Off
description: Turn off well lamp at warm-up
trigger:
  - platform: numeric_state
    entity_id:
      - weather.pirateweather
    above: 40
    below: 212
    value_template: "{{ state_attr('weather.pirateweather', 'temperature') | float }}"
condition:
  - condition: device
    type: is_on
    device_id: 308371ddf0d141b580a18890d6b25a3d
    entity_id: 4d21f6df629cdc00702c595a9a90201b
    domain: switch
action:
  - service: switch.turn_off
    metadata: {}
    data: {}
    target:
      device_id: 308371ddf0d141b580a18890d6b25a3d
mode: single

This. I don’t know what is going on here.

trigger:
  - platform: numeric_state
    entity_id:
      - weather.pirateweather
    attribute: temperature
    above: 40
    below: 212

That fixes the trigger, but the rest of your automation turns the light off if the temperature goes above 40 or falls below 212. Which doesn’t sound like it is what you were trying to achieve. Also, below 212?!

Thanks!

I posted the opposing yaml that turns the light back off when the temp is 40 or higher.

That’s what this should do. 212, 110, whatever it takes.

Remember that the numeric_state is a threshold, not a continuous check. It fires once when the temperature crosses above 40 and once when the temperature falls below 212.

  - platform: numeric_state
    entity_id:
      - weather.pirateweather
    attribute: temperature
    above: 40
    id: above
  - platform: numeric_state
    entity_id:
      - weather.pirateweather
    attribute: temperature
    below: 212
    id: below

Set that below to whatever it really needs to be.

then in your automation you use the choose option and use the condition trigger, and you can run the on and off automation in the same single automation.

Something like this?

alias: Well Lamp on
description: Turn on well lamp when freeze approaches
trigger:
  - platform: numeric_state
    entity_id:
      - weather.pirateweather
    above: 38
    below: 40
    value_template: "{{ state_attr('weather.pirateweather', 'temperature') | float }}"
condition:
  - condition: device
    type: is_off
    device_id: 308371ddf0d141b580a18890d6b25a3d
    entity_id: 4d21f6df629cdc00702c595a9a90201b
    domain: switch
    enabled: false
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              "{{ state_attr('weather.pirateweather', 'temperature') | float <= 38 }}"
        sequence:
          - service: switch.turn_on
            metadata: {}
            data: {}
            target:
              device_id: 308371ddf0d141b580a18890d6b25a3d
      - conditions:
          - condition: template
            value_template: >-
              "{{ state_attr('weather.pirateweather', 'temperature') | float >= 40 }}"
        sequence:
          - service: switch.turn_off
            metadata: {}
            data: {}
            target:
              device_id: 308371ddf0d141b580a18890d6b25a3d
mode: single

Nearly.
Your is_off condition will obviously stop the automation if the light is on.

You don’t necessarily need the second condition in the choose, you can just move all that to default actions in the choose - so the light will turn off if the first choose condition is not matched.

Great!

I had the condition disabled, but removed it, and changed to one option with default value.

Thank you so much for the help!

Where is this sort of thing documented, so I might figure it out next time?

So, how’s this?

alias: Well Lamp on
description: Turn on well lamp when freeze approaches
trigger:
  - platform: numeric_state
    entity_id:
      - weather.pirateweather
    above: 38
    below: 40
    value_template: "{{ state_attr('weather.pirateweather', 'temperature') | float }}"
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              "{{ state_attr('weather.pirateweather', 'temperature') | float <=
              38 }}"
        sequence:
          - service: switch.turn_on
            metadata: {}
            data: {}
            target:
              device_id: 308371ddf0d141b580a18890d6b25a3d
    default:
      - service: switch.turn_off
        metadata: {}
        data: {}
        target:
          device_id: 308371ddf0d141b580a18890d6b25a3d
mode: single
1 Like