Quick help with numeric condition and Attributes

First off; I am not a programmer. I was happily living my 300+ Automations with the gui and everything works. Now I am forced to get a number from inisde an atttribute and after hours and hours of googling and searching I am not seeing any success. Which is hard as I really don’t know what {{, {% and the likes do. Might as well be ancient egyptian algebra. :slight_smile:

So I have the DWD Weather integration. Which work. Inside that sensor is a wealth of information. I need the “todays high temperature mark” which resides in Attribute forecast, then the first, say, array index unter temperature.

I whacked it for a good few hours until the template development tool gave me “23” which is the highest temp for today. This is what I came up with:

{{ states.weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].temperature }}

I should install Kali Linux and call me a hacker. Woot.

Now I need this number as a numeric comparator in a condition. What I brewed together currently is:

condition: numeric_state
entity_id: weather.dwd_weather_solingen_hohenscheid
attribute: forecast
above: '22'
value_template: >-
  {{ states('weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].temperature') }}

I also tried a lot, lot, lot more. Way more. Nothing works. How close am I? And can someone please push me over the finish line for this?

Thanks :slight_smile:

Try using a template condition - rather than numeric state:

condition:
  alias: "temp above 22"
  condition: template
  value_template: "{{ states('weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].temperature') > 22 }}"

Hey,

thanks for the fast reply; I copy pasta your code into a new template condition, which is ok for saving, but clicking test yields a

template value should be a string for dictionary value @ data['value_template']. Got None

error. Not sure if that just okay or if thats somehow not working.

Sorry - forgot |int):

condition:
  alias: "temp above 22"
  condition: template
  value_template: "{{ (states('weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].temperature') | int) > 22 }}"

…shouldn’t there be a defult value nowaydays, if “int” is used? :slight_smile: I’m not sure, as I only set a default if the log calls me to do so :rofl:

Sorry :slight_smile:

Still

template value should be a string for dictionary value @ data[‘value_template’]. Got None

Yeah I always ge confused about when to provide default values. It’ll probably only fail once during startup :slight_smile:

So if you paste {{ (states('weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].temperature') | int) > 22 }} into the template editor - it should return true or false - or an error. What does it do?


That’s not the template editor (Developer tools / Template).

See this thread: Automation on temperature change - error in condition

No I meant paste the template only in the template editor in developer tools.


Sorry. Here :slight_smile:

Ah - I wasn’t going around the twist - it’s a bug…

Right place wrong template - that’s your original. This one:

{{ (states('weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].temperature') | int) > 22 }}

Because there is a bug in the GUI you will probably have to paste the condition in the raw YAML editor.


Things have changed :slight_smile:
Thanks for your help so far – mur appreciated.

So that’s because your sensor for some reason did’t provide a value??? Weird. You can provide a default by changing int to someone like int(22) but not sure why your sensor suddenly returned unknown.

You are mixing complete yaml with part yaml… it’s hard to give words to it.

The code you got before from Daryl was complete code, you need to go to the top right corner, yaml mode.
Now the GUI is gone and you can edit the complete automation in yaml.

What you did was click on the part in yaml mode and pasted a complete yaml part…

It’s hard to express in words…

You should use this template instead, but you’ll still need to insert it manually rather than with the UI editor:

{{ state_attr('weather.dwd_weather_solingen_hohenscheid','forecast')[0]['temperature']|int(0) > 22 }}

alias: 'Pool: Poolday'
description: ''
trigger:
  - platform: time
    at: '06:00:00'
condition:
  - condition:
    alias: "temp above 22"
    condition: template
    value_template: "{{ (states('weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].temperature') | int) > 22 }}"
  - condition: state
    entity_id: input_boolean.at_home
    state: 'on'
  - condition: or
    conditions:
      - condition: state
        entity_id: weather.dwd_weather_solingen_hohenscheid
        state: sunny
      - condition: state
        entity_id: weather.dwd_weather_solingen_hohenscheid
        state: partlycloudy
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.pool_heating
mode: single

I added the above via “full yaml editor” (burger menu top right → edit in yaml". Can’t save due to:

Message malformed: Expected a dictionary @ data['condition'][0]

I… I just want to check a number … :slight_smile:

Also you are mixing up your template values - I copied yours which won’t work, the one you pasted in the template editor (which is different) will work.

Rather than use either - in the editor replace value_template etc with @Troon suggestion:

   value_template: "{{ state_attr('weather.dwd_weather_solingen_hohenscheid','forecast')[0]['temperature']|int(0) > 22 }}"