Quick help with numeric condition and Attributes

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

Hey,
I had it force-run with time and it failed to run. The temperature element yields false. I bumped everything into the tempate editor: Your code is false, removing the “> 22” part shows unknown. If i put my original stuff in there it goes back to the correct temperature and even evaluates right.

Something amiss?

Oddly, this worked:


  - condition: template
    alias: Precipitation
    value_template: >-
      {{
      (states('weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].precipitation_probability')
      | int(0)) < 20 }}

Fear my copy pasta :slight_smile:

It shouldn’t work as far as I know.
You have states() which takes the state of an entity.
Inside the states() you have half a syntax for the old method to get the attribute.

I have my doubts on this method.

It does not work for me

What Paddy wrote is correct and should work.
EDIT; no there is a ) too much…

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

Didn’t work for me either.

Yep, there is! :slight_smile: After the int(0)

But the last one posted is something different. It uses “precipitation_probability” and not “temperature” as in the examples above.

So could we come back to one thing at a time? What is the actual code you’re using @creis and with what attributes should we 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

This is a corrected (removed the additional bracket) version, that should run without errors. Try this and report back, what errors come up. And please don’t change anything, just copy and paste it.

If you need something different afterwards, we can change that then, but for now, we need to establish some basics, like “is this running correctly or not?”.:slight_smile:

condition:
  - condition: template
    alias: Temperature
    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
  - condition: template
    alias: Precipitation
    value_template: >-
      {{
      (states('weather.dwd_weather_solingen_hohenscheid.attributes.forecast[0].precipitation_probability')
      | int(0)) < 20 }}
  - condition: time
    after: '05:00:00'
    before: '10:00:00'

Hey all :slight_smile:
I can confirm that with the above code the temperature and rain prediction is working like anticipated.
I can not give enought thanks to each and everyone of you guys. Without you I would not have be able to do this.

Thanks!

1 Like