Hi,
Can anybody help me to solve folowing.
How to create template where the value will be the lower temperature from two compared sensors.
Thanks
{{ [states('sensor.temperature1'), states('sensor.temperature2')] | min }}
Hi and thanks,
I have tried it in dev tools and it works as expected but if I want to add it to configuration.yaml
there is following error
missed comma between flow collection entries at line 97, column 133:
… perature_lumi_158d00052dbe2f’)] | min }}
^
This I’ve tried add to confiuration.yaml
lower_temp:
value_template: {{ [states('sensor.temperature_lumi_158d000228834a'), states('sensor.temperature_lumi_158d00052dbe2f')] | min }}
friendly_name: 'Nižšia teplota vonku'
unique_id: 1001
Can be this template under sensors?
As long as it’s a template sensor.
But perhaps you need to enclose the template in " "
It’s working now.
Thanks,
I am back,
unfortunately it is sometimes work sometimes no. Sometimes after change the input value the output value is not set correctly and value is the higher temperature.
Here is code :
lower_temp:
value_template: "{{ [states('sensor.temperature_lumi_158d000228834a'), states('sensor.temperature_lumi_158d00052dbe2f')] | min }}"
friendly_name: 'Nižšia teplota vonku'
unique_id: 1001
Hello everyone! I am having the same problem with making automation work comparing two temperatures. I live in Texas where it can be 100 degrees for days during the summer. My garage gets so hot that at times it can exceed the outside temperature. I have set up a vent that brings in air from the outside, so at night when the temp drops 5 degrees below the garage temp, the vent will turn on.
I put the following in my config yaml file:
sensor:
temperature_difference:
friendly_name: "Temperature Difference"
unit_of_measurement: '°F'
value_template: >
{{ states('sensor.garage_temperature1')|float - states('sensor.dark_sky_temperature')|float }}
It seems to work and the entity produces the correct numerical result!
The problem is for some reason the following two automation do not trigger the garage vent to turn on.
alias: Garage Vent On Summer
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.temperature_difference
attribute: state_class
above: '5'
below: '30'
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.garage_vent
mode: single
I read somewhere that using it as a condition might work so I tried this with no luck
alias: Garage Vent On Summer
description: ''
trigger: []
condition:
- condition: numeric_state
entity_id: sensor.temperature_difference
above: '5'
below: '30'
action:
- service: switch.turn_on
target:
entity_id: switch.garage_vent
mode: single
Does anyone have any ideas on what I could be doing wrong? Any help would be greatly appreciated!
Try removing attribute: state_class
from the trigger. The temperature difference’s value is included in the state of the entity, not state’s attribute.
Also, you might want to recheck the template sensor, it does not appear to follow the documentation on either the modern format or the legacy format.
Thanks so much for your quick reply. I have tried it with and without attributes, neither have worked. I will try to style the temp sensor like suggested. I am totally ignorant when it comes to coding, I just do searches and use other people’s examples. To be honest I was home free to get this template to actually work and produce the correct numerical value.
Bear in mind that numeric_state trigger will only be triggered if the value crosses your threshold. For example, starts with temp difference of 35, then go below your threshold, such as 25. If since the beginning the temperature difference is within the range of your threshold (5-30), the automation will not be triggered.
Again thanks for bearing with my ignorance! But wouldn’t something like this work if the temp difference is say 6?
alias: Garage Vent On Summer
description: ''
trigger:
- platform: state
entity_id: sensor.temperature_difference
from: '5'
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.garage_vent
mode: single
Would a value of 6 not cross the threshold of “from” 5?
You have to be careful using state triggers like that because they are very literal and will only trigger if the value goes from exactly “5” to something else. In the case of temperatures that are only polled every so-many seconds or minutes it is very likely that you might see something like a jump 4.9 to 6.2… this would not trigger your automation.
This automation would also have the problem of turning the fan “on” if the temp difference went from exactly 5 to 3.5. The numeric state’s “above” and/or “below” help prevent those kind of inverted trigger firings.
Also, when dealing with fan motors it is usually advisable to make sure your automation avoids “bouncing” the power on and off if the value of your sensor is hovering around one of your set points. This can be done by adding a delay at the end of you “on” automation or a “wait” or “wait for trigger” near the beginning of your “off” automation.
Thanks so much for your help! So I guess the above and below values don’t matter? Setting it up between 5 and 30 sure did not work! So how do you trigger an automation using an entity that reports numbers? I am completely confused. I guess I should have paid more attention to the computer science course I took 30 years ago lol.
You were pretty close to the basic “turn on” automation with your earlier attempt, but you need to incorporate the suggestions that ardysusilo gave you…
This is the current format for Template Sensors (Adopted Jun '21)
template:
- sensor:
- name: temperature_difference
unit_of_measurement: '°F'
state: >
{{ states('sensor.garage_temperature1')|float - states('sensor.dark_sky_temperature')|float }}
alias: Garage Vent On Summer
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.temperature_difference
above: 5
below: 30
for:
minutes: 5
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.garage_vent
mode: single
Adding the 5 minute “for” to your trigger will help keep the power from bouncing between on and off. Remember that it will only trigger when the value of the sensor crosses one of your set points, so it isn’t going to start up as soon as you save the automation.
To test whether the automation is working you can manually manipulate the temperature difference sensor’s value in the Developer Tool’s > State menu. Put “sensor.temperature_difference” in the “Entity” field, then set the value to something outside of you trigger range by typing the value ( let’s use 0) into the “State” field. Press the “set state” button. Give it a few seconds to register, type a value inside your range ( let’s use 10) in the “State” field, press the “set state” again, and wait for those 5 minutes we added to the trigger to go by…
From there you will need to decide how you want to automate turning it off…
Thank you so much! I have been trying to make this work for months, trying everything before reaching out! This seems to have worked! 5 minutes later they vent kicked on! Again thanks for you and Ardy’s help I learned a lot!
Happy to help.
One thing I forgot to suggest… If you want this to be a set-it-and-forget-it, Summer-only automation make sure to add a condition that takes the outside temperature into account so it’s not running when it’s too cold outside…
condition:
- condition: numeric_state
entity_id: sensor.dark_sky_temperature
above: 60
Thanks so much! I had set up separate automation for winter, this makes more sense!
Question - are you manually turning off this vent fan?
Or do you have an automation that turns it off when the temp difference is less than 5 degrees?
Something similar to a “do while”?