Howto use temperature from weather.home as trigger?

Hi guys

I am trying to use the outside temperature to close the curtains by using the weather.home entity.
Searching here and in the docs gave me this:

- id: '1590702116486'
  alias: test temp
  description: ''
  trigger:
  - below: '12'
    entity_id: weather.home
    platform: numeric_state
    value_template: '{{ state.weather.home.temperature }}'
  condition: []
  action:
  - data: {}
    entity_id: media_player.1
    service: media_player.media_pause

but that doesn’t seem to work.
Am I missing something/doing wrong?

Thank a lot in advance!
Nick

To get the state value, use this format:
value_template: '{{ states.weather.home.temperature.state }} or states("weather.home.temperature")

But if it is a weather entity, the temperature is not in the state but in an attribute, so you should use this: states.weather.home.attributes.temperature

8 Likes

THANK YOU @briis, that did the trick! :partying_face:

With this solution, I have searched again in the forum & docs but couldn’t find a lot.
The reason I’m saying this: I’m curious about how could I have found this solution?

Thanks, have a nice day!
Nick

1 Like

Hi Nick,
O learned the way you just did, by asking in this Forum and searching for something that was similar to my issue. Specifically for Yaml stuff like this, I can recommend that you use the Developer Tools (Found in the menu on the left side) and then Template to test stuff out. That has really helped me a lot, because you see if you get the values you expect, without having to restart HA all the time.

3 Likes

Ah OK, that’s what you’re doing after cycling… :grin:

Thanks a lot for that tip to use templates, another thing learned!

Have a nice day
Nick

2 Likes

Hey there!

I’ve very new to HA, but already love it with all my heart. I’ve looked through lots of posts, but this one seems to be the closest to what I’m chasing down. My wife and I live in a tiny house on wheels and often need to hack our water source. But each winter I’m faced with a similar challenge of how to keep out water supply from freezing. Last year (pre home assistant) I came up with something that worked quite well! I used IFTTT to trigger a Smart Life scene that would allow a small amount of water to trickle down the drain should the temperature go below freezing. (In some situations, that could be considered wasteful, but not so in ours). It kept 150’ of hose just laying on the ground from freezing all winter long! I’ve refined the idea significantly since then and am all set for it to run, but can’t seem to get the trigger to work! Any help would be greatly appreciated as the temperature has just begun its frosty descent!

Here’s my two automations:

- id: '1605217304373'
  alias: Trickle Off (auto)
  description: ''
  trigger:
  - below: '32'
    entity_id: weather.home
    platform: numeric_state
    value_template: '{{ states.weather.home.attributes.temperature }}'
  action:
  - scene: scene.trickle_off
  mode: single
- id: '1605217449763'
  alias: Trickle On (auto)
  description: ''
  trigger:
  - above: '32'
    entity_id: weather.home
    platform: numeric_state
    value_template: '{{ states.weather.home.attributes.temperature }}'
  action:
  - scene: scene.trickle_on
  mode: single

I made it with the frontend scene and automation functions, but because the switch only registers as an entity and not a device, I made a scene using some tp-link switches, changed the entities in the .yaml then had the automation activate the scene… It works when I hit “execute” but the temp trigger doesn’t work. Any insight on how to register an entity as a device would be amazing! Also, how important is the id#? I’m only a few weeks into this and have loads of basics to learn.

Thanks for reading! Sorry for the longwinded explanation!

Hi, I’m not an expert at all either but will give it a try…
It’s possible that you have to play with spaces.

action:
- data: {}
  entity_id: switch.your.switch
  service: switch.turn_on 
 
1 Like

You don’t need the value_template anymore, so change your triggers to the below, and it should work.

Trickle Off (auto)

  - platform: numeric_state
    entity_id: weather.home
    attribute: temperature
    below: '32'

Trickle On (auto)

  - platform: numeric_state
    entity_id: weather.home
    attribute: temperature
    above: '32'
3 Likes

Thank you so much for the help!

It seems to be working- but I’m realizing the refresh rate might be very long?


I thought it wasn’t working and left it alone, to research later, but then it looks like an hour later it turned on!

Here’s the automations:

  mode: single
- id: '1605217304373'
  alias: Trickle Off (auto)
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: weather.home
    attribute: temperature
    above: '32'
  action:
  - scene: scene.trickle_off
  mode: single
- id: '1605217449763'
  alias: Trickle On (auto)
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: weather.home
    attribute: temperature
    below: '32'
  action:
  - scene: scene.trickle_on
  mode: single

The timing fully depends of the refresh timing of the Weather Entity you use. If that is hourly, then the state of the temperature value will only change once an hour.
In my view this automation depends on very local temperature data, and as you only need the temperature value, I would recommend you acquire a device that can measure Temperature, and that is suited for outdoor use. Then take the temperature value from this device, instead of the weather entity.

There are many device types out there that can do this, but what you should buy depends on your setup (Zigbee, Zwave, WiFi etc).

1 Like

You’re totally right. I just set up a trigger, using what you showed me, with one of my indoor Wireless Sensor Tags and the trigger is instant.

(I also really like that it’s continuous; in that, if while the trigger is within the set threshold, even if I manually deactivate it, it automagically pops right back on.)

Thank you guys! Feeling confident to face the winter!

1 Like

Okey doke! So I ordered a Sonoff TH10 (which arrived very quickly) and have it all set up. It seems to be reporting in celsius so I changed the values to account for it. Other than that, I really just linked it to HA and swapped the entity_id. It’s currently about 14 degrees celsius here, so I ran a test with the trigger set to below: ‘15’; even after waiting ten minutes and restarting HA multiple times, it still isn’t triggering. :face_with_monocle: Any thoughts? Again, very grateful for your time! (If this is getting annoying, would it be better for me to start a new topic on the boards? I’m really not sure what the etiquette is! haha)

Current automations:

- id: '1605217304373'
  alias: Trickle Off (auto)
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: switch.sonoff_outsideprob
    attribute: temperature
    above: '0'
  action:
  - scene: scene.trickle_off
  mode: single
- id: '1605217449763'
  alias: Trickle On (auto)
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: switch.sonoff_outsideprob
    attribute: temperature
    below: '0'
  action:
  - scene: scene.trickle_on
  mode: single

Hi Joey,
When you have a trigger that says above or below the trigger will ONLY fire when the entity state changes to a value lower or higher than that. So in your case, the value was 14 and you want it to do something if it goes below 15, that will never fire, as you are already there. Try experimenting with other values, and see if it does not do what you want.

Thank you again for your insight!

What do you think of this?
The temperature is certainly below 60 (48 in fact), yet the Night Light remains off!
I’ve restarted HA. I’ve also verified that the action works by clicking ‘EXECUTE’ on the frontend. It appears to be something with the trigger.

automation:

- id: '1605968877142'
  alias: Test with Night Light (onifbelow60)
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.outside_temperature
    below: '60'
  condition: []
  action:
  - type: turn_on
    device_id: 16dede88ff7511eaa8ecf30064ace3b9
    entity_id: switch.night_light
    domain: switch
  mode: single

PS
I made a sensor out of the TH10’s attribute, using this, which was very exciting lol

- platform: template
    sensors:
      outside_temperature:
        friendly_name: "Outside Prob"
        unit_of_measurement: '°F'
        value_template: '{{ ((states.switch.sonoff_outsideprob.attributes.temperature)* 9 / 5)+ 32|round(1) }}'

It might still be the issue I described before: This automation will ONLY trigger, when the state goes from something higher than 60 to below 60. So if you restart HA, and the temperature is 48, it will not trigger, but it will trigger if the temperature goes to 61 and then back to 59.

So basically things should work when the temperature goes up and down and passing the thresholds

You could add an automation that ensures this is run when you restart HA:

alias: Home Assistant Startup
description: ''
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - service: automation.trigger
    data: {}
    entity_id: automation.YOUR_AUTOMATION_NAME
mode: single

OR you could play with the new Choose template in Automations. The below example will trigger on any change of the temperature sensor, and then either turn off or turn on. You will get some Turn On and Turn Off’s even if the entity is already On or Off, but that does not really matter, I guess. If you create a new Automation, and click the three dots in the upper right corner, you can switch to yaml mode and copy the below directly.

alias: Test Temperature
description: ''
trigger:
  - platform: state
    entity_id: sensor.outside_temperature
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.outside_temperature
            below: '60'
        sequence:
          - service: switch.turn_off
            data: {}
            entity_id: switch.night_light
      - conditions:
          - condition: numeric_state
            entity_id: sensor.outside_temperature
            above: '60'
        sequence:
          - service: switch.turn_off
            data: {}
            entity_id: switch.night_light
    default: []
mode: single```
2 Likes

Oh I see! I’m sorry. That just didn’t click right away. Thank you so much for the help! Everything is working reliably now!

1 Like