Hi
I need to create 2 sensors or templates not sure yet.
The first one is regarding my hot water temperature sensor. = sensor.temperature_purifier
Right now is at 65.
I need to make a trigger when its temperature raise to 66 for example.(template or sensor?)
I only need to triiger once when and if it’s value raised.
Either way I don’t know how to start.
The second one I find it even more difficult.
I have a start point at 21 of December. Its value is 133,44. I want each day to add 0.25 so 22 Dec = 133,69 and so on. From 21 of June I would like to the value of 20th of June to reduce for 0.25 and keep reducing for 0.25 until the 21 of December.
This I guess should be a sensor (I?) in order to compare it with sun azimuth.
My problem is as I mention that I don’t know how to begin. If someone can give me an example it would be very helpful.
This sounds more like you want an automation. What is it that you want to happen when your temp sensor gets above 65 degress ?
What are you doing with this value ?
Home Assistant already calculates sunrise / sunset for your current location to which you can add a time offset. Would this be helpful ?
Paste this into the Template Editor and experiment with it. To test it, change the month and day of the first line and observe the result. For example it is currently set to June 26 (month=6 day=26).
{% set today = now().replace(year=2020).replace(month=6).replace(day=26).replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{{ today }}
{% set dec21 = now().replace(month=12).replace(day=21).replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set jun21 = now().replace(month=6).replace(day=21).replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set previous_dec21 = now().replace(year=now().year-1).replace(month=12).replace(day=21).replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set jun20_value = 133.44 + ((jun21 - timedelta(days=1)) - previous_dec21).days * 0.25 %}
June 20 value is: {{ jun20_value }}
{% if today >= dec21 %}
A) {{ 133.44 + (today - dec21).days * 0.25 }}
{% elif today < jun21 %}
B) {{ 133.44 + (today - previous_dec21).days * 0.25 }}
{% else %}
C) {{ jun20_value - ((today - jun21).days * 0.25) }}
{% endif %}
I overlooked to mention that if you plan to use this Template Sensor in version 0.117 then it will update every minute. If you want to use it with an older version, we need to add a reference to sensor.time in the template.
The sensor is perfect! I am trying to “read” your code and I don’t understand most of it…
I need the sensor to update once every morning (I think).
I will update to 0.117 but after the 0.117 .2 or .3 in order to be stable.
As it is right now in 0.116.4 how often this sensor updates?
In 0.117 version I would to prefer to update a lot than per minute since I only need the day value once per day.
Correct. However, in 0.117 you can remove it because the now() function will automatically cause the template be updated every minute.
If you’re thinking “But I don’t need this Template Sensor to be updated every minute (1440 times a day), once a day is enough” that has been discussed with the development team and they feel the extra processing is not a burden for Home Assistant.
NOTE
It’s possible to perform all of the date calculations without using the now() function. It can be based on sensor.date but it’s not quite as neat as using now().
the hot water temperature values varies a lot. the minimum usually is 30 and the maximum is 70 lets say.
My purpose is to catch up the first time when the temperature rises. from 30 to 31 or 50 to 51 etc
in order to achive this should I use something like
In a Numeric State Trigger, the above option is a threshold. The moment the value increases above the threshold, the trigger occurs. For example, this automation will be triggered when the value of sensor.temperature increases above 50.
It will not trigger again if the value continues to increase to 52, 53, etc. It only triggers when the value crosses the threshold. To reset the Numeric State Trigger, the value must first fall below the threshold (below 50). The next time it increases above 50, it will trigger the automation again.
If you want an automation to be triggered when the temperature rises above two thresholds, you can use two Numeric State Triggers:
Forcing a temperature sensor’s value is an unusual procedure. Your forced value will last only as long as the next temperature measurement is received by the sensor. For example, if the sensor reports 34 at 00:59 and you set it to 42 at 01:00, it will change back to 34 (or some other value) the next time the sensor gets a new measurement (possibly as soon as 01:01).
Probably, I didn’t express it right, and I forgot to mention that this is for my Solar Water Heater
I mean, if at 01:00 o’clock the sensor temperature is at 30 or 35 or 70 or whatever value it will be
then ideally I need this value to be the threshold (“above”) so as to understand when the sun start heating the water
The template gets the value of sensor.temperature, converts it to a floating point number, then checks if it is greater than 50. If it is, the automation is triggered.
If we replace 50 with an input_number, we can adjust the value of the input_number (either via the UI or by an automation).
Here’s a simple automation to set the input_number to the sensor’s value at 01:00.
trigger:
platform: time
at: '01:00:00'
action:
service: input_number.set_value
data:
entity_id: input_number.threshold_temperature
value: "{{ states('sensor.temperature') | int }}"
Of course, the actual automation will need to be more sophisticated because at some point you will want it to set input_number.threshold_temperature back to the preferred values (30 or 50 or whatever it is you wish to use).
That’s not a good indicator. All Template Sensors are updated at startup. If they lack entities, they will never be updated again (until the next restart). This template lacks entities, which is why I suggested to include the line containing sensor.date. It changes state at the beginning of every new day, thereby causing the Template Sensor to be updated at that same moment.
The fact it failed to do that today implies something is wrong.
Did you add and configure the Time & Date integration (sensor.date) yesterday or was it already installed?
If you added it yesterday, did you restart Home Assistant afterwards?
After you added the suggested line to the template, did you execute Reload Template Entities (or restart Home Assistant)?
If you did all those things and the Template Sensor still failed to update automatically today, something somewhere isn’t working correctly.