Hi, I am trying to set a value based on the day number. If it is the 1st of each month I would like the sensor to default to 100. Else I would like the value of the sensor to default to something else (this value is calculated based on the predicted solar and works fine)
For some reason I cannot carry out the check on if it is the first day of the month or not. I am sure its simple but alas I am stuck!
I have tweaked that as per your code, but it keeps jumping to the ‘do_something_else’ output (I am setting the comparison to ‘8’ as its the 8th today
Interestingly if I change the value it makes no difference, but if I change it to greater than 8 it then goes to ‘do_this’. But then when changing the value it remains on the ‘do_this’ output
- platform: template
sensors:
day_number:
friendly_name: Day of the Month
value_template: '{{ now().day }}'
target_soc:
friendly_name: Target SOC for Night Charge
unit_of_measurement: "%"
value_template: >-
{% if states('sensor.day_number') == '8' %}
100
{% else %}
{% set state = 2.5 * states('sensor.solcast_forecast_today') | float(0) %}
{% set state = 150 - state | float(0) %}
{% set y = (((state/5) | int(0)) +1) * 5 %}
{{ ([35, y, 95] | sort)[1] }}
{% endif %}
NOTE
Although unrelated to the problems you have encountered, you should consider using modern format to configure Template Sensors. You’re using legacy format which, although still accepted, won’t receive any enhancements in the future.
However, if you use a line-continuation character, like > or |, to indicate that the template begins on the next line, the template should not be wrapped in quotes. If you do wrap it in quotes, the quotes will become part of the result produced by the template.