Need help with external temperature and automation use

I am looking to check the external temperature at a set time and if it is below a set value turn on a couple of items for 30 minutes then turn them off. The code below doesn’t work I am guessing as weather.assistant doesn’t have a specific temperature entity. Is this an easy fix?

 id: '1587318371965'
  alias: Cold morning
  description: ''
  trigger:
  - at: 05:45
    platform: time
  condition:
  - condition: and
    conditions:
    - below: '4.0'
      condition: numeric_state
      entity_id: weather.homeassist
  action:
  - device_id: dda51d3f28b34a469db34a5f3a19c0a2
    domain: switch
    entity_id: switch.item1
    type: turn_on
  - device_id: dcc858ce19a944c48fcf13a6eaad89a3
    domain: switch
    entity_id: switch.item2
    type: turn_on
  - delay: 0:30
  - device_id: dda51d3f28b34a469db34a5f3a19c0a2
    domain: switch
    entity_id: switch.item1
    type: turn_off
  - device_id: dcc858ce19a944c48fcf13a6eaad89a3
    domain: switch
    entity_id: switch.item2
    type: turn_off

What are the attributes available for this:

Look in the developer tools states menu.

Can I just add temperature: to the code then?

No, you will need a template to check the attribute. Also you don’t need to specify and for your conditions as they are and by default. Plus you only have one condition, so nothing to and it with. Try this:

- id: '1587318371965'
  alias: Cold morning
  description: ''
  trigger:
    platform: time
    at: '05:45'
  condition:
    condition: template
    value_template: "{{ state_attr('weather.homeassist', 'temperature')|float < 4 ) }}"
  action:
...etc

One more thing, if you restart home assistant while the 30 minute delay is running the devices will not turn off.

To prevent this write another automation to turn the devices off at 06:15 rather than using a delay.

- id: '1587318371965'
  alias: Cold morning on
  description: ''
  trigger:
  - at: '05:45'
    platform: time
  condition:
    condition: template
    value_template: "{{ state_attr('weather.homeassist', 'temperature')|float < 4 ) }}"
  action:
  - device_id: dda51d3f28b34a469db34a5f3a19c0a2
    domain: switch
    entity_id: switch.item1
    type: turn_on
  - device_id: dcc858ce19a944c48fcf13a6eaad89a3
    domain: switch
    entity_id: switch.item2
    type: turn_on

- id: 'blahblah0100101'
  alias: Cold morning off
  description: ''
  trigger:
  - platform: time
    at: '06:15'
  action:
  - device_id: dda51d3f28b34a469db34a5f3a19c0a2
    domain: switch
    entity_id: switch.item1
    type: turn_off
  - device_id: dcc858ce19a944c48fcf13a6eaad89a3
    domain: switch
    entity_id: switch.item2
    type: turn_off
1 Like

@tom_l perfect, thank you so much that all makes sense. I am moving over from Domoticz so as you can guess yaml etc. is a whole different kettle of fish to what I am used to doing. I have a number of these type of items that I have on my current setup so this will help me immensely.

1 Like

Hmm, it’s not working. I have also tried the following and it doesn’t work.

is_state_attr('weather.homeassist', 'temperature', <5)

Maybe I should look at this differently and somehow assign a variable or an entity that will sample ‘weather.homeassist’, ‘temperature’ say every 10 minutes then use all my automations that need it to reference this single item?

Create a new sensor :

  - platform: template
    sensors:
      outside_temperature:
        friendly_name: "Outside Temperature"
        unit_of_measurement: '°C'
        value_template: "{{ state_attr('weather.homeassist', 'temperature') }}"

Then you can use this sensor in your automations.

1 Like

@francisp that’s it. Perfect that’s exactly what I need and I can use it in my other automations as well.

Because that is not what I wrote. I wrote:

state_attr('weather.homeassist', 'temperature')|float < 4 )

Unfortunately the extra bracket I somehow included on the end after the 4 would have prevented the config check passing. Remove that and it should have worked.

1 Like

I was just saying that I tried that other line (is_state_attr) that I saw elsewhere and it didn’t work either. As you say it must have been the extra bracket that caused it to fail. At least now I have two different options that I can use going forward. Thanks to you both, much appreciated.

1 Like