Automation using template comparing 2 sensors values

Hi Andre,
Does your sensor.humidade_wc_last_hr.attributes.mean works ? when you use the developper tool do you have a value using

{{ states('sensor.humidade_wc_last_hr.attributes.mean') | float}}

?
Cause this should work

Hello budcalloway,

Actually in developer tools I’m not getting data.

How can I use this atribute value in Automation?

image

Thanks

What do you have in the “States” tab ?

You have the format mixed up… either of these two will work (the top one is preferred):

{{ state_attr(‘sensor.humidade_wc_last_hr’, ‘mean’) | float(0) }}

{{ states.sensor.humidade_wc_last_hr.attributes.mean | float(0) }}

Hello Didgeridrew,

Thanks a lot for the help.
Now I’m struggling to make the automation work.

I intent to use Automation Template Trigger with two sensors like this:

{% if state_attr('sensor.humidade_wc_last_hr', 'mean') | float(0) < states('sensor.bme_3_relative_humidity') | float(0) %}true{% endif %}

But it seems that is not actually working, in dev tool-template, this is what I get:

Thanks

Your template is working correctly. The template is false and you did not tell it what to do in that case, so it returned nothing…

For a your purposes you don’t need an if statement… all you should need is:

{{ state_attr('sensor.humidade_wc_last_hr', 'mean') | float(0) < states('sensor.bme_3_relative_humidity') | float(0) }}

Thanks a lot Didgeridrew.

It’s finally working.
So now if the mean humidity of last 2 hours (plus 10%) is less that actual humidify it will trigger the VMC to level 3.

- id: '1637154302262'
  alias: WC - Humidade VMC nível 3
  description: se humidade atual acima humidade média+10%, vmc nível 3
  trigger:
  - platform: template
    value_template: '{{ state_attr('sensor.humidade_wc_last_hr', 'mean') 
      | float(0) * 1.1 < states('sensor.bme_3_relative_humidity') | float(0) }}'
  condition: []
  action:
  - service: mqtt.publish
    data:
      topic: ventilation/ventset
      payload: '3'
      qos: '2'
  - service: notify.mobile_app_mi_a2
    data:
      data:
        ttl: 0
        priority: high
      message: WC Hum VMC n3
  mode: single
2 Likes

Hello again Didgeridrew,

This is a little bit off topic, but maybe you can guide me on how to create a sensor to get the value of 24hr ago.

Tks

Hi everyone!

Can someone help me with the templates below?
Both value templates give me an error when I test them.

This is the error I get:

image

action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ states('sensor.multisensor_basement_humidity') | float >
              states('input_number.basement_max_humidity') | float }}
        sequence:
          - service: humidifier.set_mode
            data:
              mode: Dry
            target:
              entity_id: humidifier.dehumidifier_bsmnt
      - conditions:
          - condition: template
            value_template: >-
              {{ states('sensor.multisensor_basement_humidity') | float <=
              states('input_number.basement_max_humidity') | float }}

I don’t understand what is wrong with the templates. Anyone sees the mistake?

Thank you!

Your float filters will need defaults. However, the error is due to the fact that the UI condition tester in the automation editior does not currently work for Template conditions.

1 Like

Didgeridrew is right.
I’d add that if you want to test your templates, do it in the dev tools