Quick help with numeric condition and Attributes

…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 }}"
alias: 'Pool: Poolday'
description: ''
trigger:
  - platform: time
    at: '06:00:00'
condition:
  - condition:
    alias: "temp above 22"
    condition: template
    value_template: "{{ state_attr('weather.dwd_weather_solingen_hohenscheid','forecast')[0]['temperature']|int(0) > 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

yields

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

This should work:

alias: 'Pool: Poolday'
description: ''
trigger:
  - platform: time
    at: '06:00:00'
condition:
  - condition: template
    alias: "temp above 22"
    value_template: "{{ (state_attr('weather.dwd_weather_solingen_hohenscheid', 'forecast')[0]['temperature']) | int(0)) > 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

Woot! The above was able to save… Let’s hope it actually works :slight_smile:

THANKS EVERYONE. I would not have done this in 10 years.
I live happily in the GUI editor. There is cake there. And no pain :slight_smile:

1 Like

Ah - the old missing brackets (plural)… :smiley:

Thanks @paddy0174 for the pickup.

1 Like