Hello all,
I am despairing of the automation time trigger:
The following scenario:
I want to open my shutters at a certain time. To do this, I define the time parameters for weekdays, weekends and holidays via the frontend.
I have a template that calculates the opening time “today”.
On the desktop the template entity is displayed very well, e.g. “07:30:00”.
However, when I use the entity as a time trigger in an automation, the trigger does not fire!
I have already tried everything, e.g. also device_class: timestamp or state_attr(as_timestamp(…)), direct use of the entity without states(), … - but all that always results in error messages.
It seems that the template just does not want to be a timestamp type, even though it looks correct on the desktop.
When I use the input_timedate entities directly as time triggers in automation, the trigger fires. So it can’t be the entity itself.
I’d do this by triggering off all of the input datetimes, and use or’d template conditions to choose whether to proceed. No need for the template sensor then.
condition:
- or:
- "{{ is_state('binary_sensor.holiday_sensor', 'on') and trigger.entity_id == 'input_datetime.fire_time_holiday' }}"
- (add the other two yourself, I'm on a phone! )
- (make sure they exclude it being a holiday)
I think your quotes in the friendly_name will be causing a problem. You could create this template sensor in the UI: use the same template in the State Template box.
thanks a lot!
As an HA newbie and still have a lot to learn… ;D
And will asap try your suggestion!
Sry, the “double quotes” are a typical german thing, in reality they are both upper (" " - probably a copy&paste issue) and don’t make any trouble, but anyway I’ll try hard to get used to ‘single quotes’ …
In that case, your original plan to use a Template Sensor was correct, just that you needed to configure it correctly as explained in my previous post.
If you are interested, you can use the streamlined version of the template in the Template Sensor.
sensor:
- platform: template
sensors:
next_fire:
friendly_name: "Today’s time to fire"
device_class: timestamp
value_template: >
{% set entity = 'holiday' if is_state('binary_sensor.holiday_sensor', 'on')
else 'weekend' if now().weekday() in [5, 6]
else 'weekdays' %}
{{ today_at(states('input_datetime.fire_time_' ~ entity)).isoformat() }}
In that case, I don’t think you used my example exactly the way I posted it above. However, that’s not important at this point, only that the template ultimately produces a proper ISO 8601 timestamp.
Glad to hear it fixed the problem.
Please consider marking my post above with the Solution tag. Only you, the author of thiis topic, can do that (or a moderator) and it will automatically place a checkmark next to the topic’s title. This signals, to other users who may have a similar question, that this topic has been resolved
You might be right: I needed to adopt your solution, as my specific program is full of german expressions that i didn’t want to bother anyone in this post… anyway, it works and you made my day (resp. night )
Well, this lesson was really very instructive and I am glad that now I know this and can deal with it.
Meanwhile, I’ve also learned that I could have solved it differently: I didn’t realize that I could query in the ‘action:’ section with further conditions in if…then clauses. In this respect, a single automation is actually enough for my original purpose - but what the heck…
I also find it interesting that you can identify multiple triggers by using ‘trigger_id’ and even within a single automation formulate specific conditions depending on which trigger has fired… this could also be very helpful for me - I already have a use case in mind…
I’m almost afraid that HA is so diverse and powerful that I’ll never grasp and understand all its functions, even if they were actually useful to me…