123
(Taras)
July 20, 2021, 7:50pm
13
To be clear, there was nothing wrong with the automation’s trigger. Changing it from a Numeric Device Trigger to a Numeric State Trigger reduces the number of lines of code but doesn’t change the behavior (two ways of creating the same kind of trigger).
Reducing the Numeric Trigger’s threshold value and then reloading automations serves to reset the trigger.
What was definitely incorrect was arithmetically comparing two state
values without first converting them to numeric values.
Well thank you for your help ! I was not far from the goal but I would have missed this important part !
For me it is time to sleep ! I juste have to wish you a pleasant afternoon
See ya
Great it’s working!
If you wouldn’t mind, please mark the post from Taras
as solution (the checkbox under his first post). Helps others to see the solution at first glance! Thanks!
And a pleasant afternoon to you, too from the balcony looking in the night sky.
yes !!! I already checked the box as solution !
Taras,
I don’t know if I can add another question in the same topic but it is related.
I was wondering if it was possible to make some kind of mathematic operations like :
{{ states('sensor.sonde_sdb_bas_humidity') | float < states('sensor.sonde_salon_humidity') +2 | float }}
Thanks
123
(Taras)
July 21, 2021, 7:59pm
18
Yes but the example you posted contains a small error.
states('sensor.sonde_salon_humidity') +2 | float
^
|
You cannot add 2 to the sensor's value here.
You can add 2 to the sensor’s value after it has been converted.
states('sensor.sonde_salon_humidity') | float + 2
Here’s your corrected template:
{{ states('sensor.sonde_sdb_bas_humidity') | float < states('sensor.sonde_salon_humidity') | float + 2 }}
1 Like
Super ! Thanks I just figured it out using the forum
Thanks again ! Hope that one day, I will be able to help others here !
1 Like
Andre_Magro
(André Magro)
November 13, 2021, 10:26pm
20
Hello,
I intend to do something similar also to automate a VMC unit based on humidity of a bathroom, but I want that the trigger occurs based on value from two sensors. One is the humidity’s mean of last 2hr, and the other is the actual humidity.
I already created the statistics sensor to get humidity’s mean.
I’m using Triggers type - Template, and this is the code:
platform: template
value_template: |-
{{ states('sensor.humidade_wc_last_hr.attributes.mean') | float <
states('sensor.bme_3_relative_humidity') | float }}
I’m getting this error: “Message malformed: Integration ‘’ not found”
Thanks
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?
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) }}
Andre_Magro
(André Magro)
November 16, 2021, 10:15pm
26
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:
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.
opened 01:22PM - 08 Apr 22 UTC
### The problem
In order to implement a somewhat more complex template conditio… n, I came across the problem that (at least testing) templates conditions do not work (anymore).
What I did:
Create a simple automation having a template condition:
```
- condition: template
value_template: "{{ 1 > 2 }}"
```
So, this is extremely simplifed. The expression should return False, but instead I get the following error when testing this expression in the condition frontend (under automatisations):
`Error handling message: template value should be a string for dictionary value @ data['value_template']. Got None (invalid_format)`
If I enter the same snippet of code in the templates section un der developer tools, it prints false.
Either there is a problem in the code just adding the template condition in the automatisation frontend or something is completely borked.
### What version of Home Assistant Core has the issue?
2022.4.1
### What was the last working version of Home Assistant Core?
_No response_
### What type of installation are you running?
Home Assistant Container
### Integration causing the issue
Automation
### Link to integration documentation on our website
_No response_
### Diagnostics information
_No response_
### Example YAML snippet
```yaml
- condition: template
value_template: "{{ 1 > 2 }}"
```
### Anything in the logs that might be useful for us?
```txt
2022-04-08 14:40:54 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140209354674720] Error handling message: template value should belue_template']. Got None (invalid_format)
```
### Additional information
_No response_
1 Like
Didgeridrew is right.
I’d add that if you want to test your templates, do it in the dev tools