#Conditional trigger_variable
1 messages · Page 1 of 1 (latest)
You could set up a template to return the two different times depending on the workday variable (either in the trigger itself, or make a template sensor that the trigger looks at)
Or you could set up the automation to trigger at both times every day and use conditions to only pass through to actions on the right trigger on the right type of day
Hi @oblique yarrow,
I always recommend triggering more general, and using Conditions: to narrow it down. You don't need to deal with limited templates and variables that are not available, and it just works better.
Change your thinking. Use the conditions...
Something like:
description: ""
mode: single
trigger:
- platform: time
at: "10:00:00"
id: workday
- platform: time
at: "12:00:00"
id: weekend
condition:
- condition: or
conditions:
- condition: and
conditions:
- condition: trigger
id:
- workday
- condition: state
entity_id: binary_sensor.workday_sensor
state: "on"
- condition: and
conditions:
- condition: trigger
id:
- weekend
- condition: state
entity_id: binary_sensor.workday_sensor
state: "off"
action: []
Agreed...
I hear ya guys.
I think I'm still a little confused, especially about the sample code...
The automation triggers at 2 times. It then hits a conditional, with "workday" + workday_sensor on OR "weekend" + workday_sensor off. But then that or conditional goes to the same action...
Where does the decision about time/day split?
Also, I think what you guys are saying is to have different actions based on a conditional, but doesn't this double the size of the code?
Thanks!
the way the condition "layer" works is that it stops the automation unless it evaluates to true, but the same action block gets run for workdays at the workday time, and weekends at the weekend time when that big condition is returning true
workdays at weekend time, weekends at workday time, it won't run any actions
if you want it to run different actions based on whether it's a workday/weekend trigger you need to put the if statement inside the actions, rather than the conditional
Gotcha. 👌 Makes sense.
Why even have those conditionals? Don't the triggers essentially do the same thing?
The triggers go off every day at the two times, the "id" line is just so we can tell which of the triggers went off in the condition
Ah. Right. 🫣🤦♂️
Awesome, thank you! I'll give it a go when I get home 🤙
You can leave this open for a while to collect other ideas, but when you have a solution, would you be so kind as to select close from the 3 dots menu in the top and the Resolved tag if you have not already done so?
Aaaah. Will do!