Here’s the code I have, but I suspect something that I’ll explain below:
- alias: 'Turn On Entertainment Center Jon'
trigger:
- platform: state
entity_id: device_tracker.jons_iphone_7
to: 'home'
condition:
condition: and
conditions:
- condition: sun
after: sunset
after_offset: "-1:00:00"
- condition: time
before: '22:00:00'
action:
- service: switch.turn_on
entity_id: switch.entertainment_center
My understanding of a trigger is that the change needs to happen during the time tested by the condition.
So for this automation, I think I may have screwed up thinking that the system is going to persistently check at all times the state of my iphone (line 4) when in fact it will only perform the action if the trigger is fired inside of the times specified in the condition.
Am I correct in thinking this?
If so, how would I change this to ensure that my location is always a consideration?
Should I run a time platform trigger with a one minute cycle or is that excessive?
Turn on your entertainment system when
a) the time is 1 hour before sunset AND
b) before 2200 but only when
Your state is changed to home
this state chang is from anything to home. It is usually best practice to use not_home to indicate that you are indeed coming home.
You don’t have to worry about running this in cycles. It just fires when the criteria is met. No need for excess.
So, I’m still a bit confused. If I’m already home prior to the 1 hour offset and I remain home through 22:00:00, then the trigger will never change. It will already be at home. To remedy that, I figured I would put a time trigger that would check a state condition on the phone since no change will occur.
If I used from: ‘not_home’ would that be a better way to trigger? Although I don’t see that an event would actually be happening.
The more I think about it, and i’m a bit fuzzy too because I haven’t had much sleep in the last 2 days, but I think you’re gonna have to have go with your initial one, but add an additional trigger… bare with me. i apologize…
add a second trigger that checks for your phone state. If it’s currently home then it will fire, oooorrrrr, if it changes to home it will fire…
- alias: 'Turn On Entertainment Center Jon'
trigger:
- platform: state
entity_id: device_tracker.jons_iphone_7
to: 'home'
- platform: state
entity_id: device_tracker.jons_iphone_7
state: 'home'
condition:
condition: and
conditions:
- condition: sun
after: sunset
after_offset: "-1:00:00"
- condition: time
before: '22:00:00'
action:
- service: switch.turn_on
entity_id: switch.entertainment_center
what should happen is that between that time if you’re home it will fire, and when you arrive home it will fire. I think… My head is all warped from cleaning up my automations all day but I think this should work for you
So, I understand the spirit of the trigger setting in this example, but I’m still unclear about how the system would repeatedly run a check on the trigger because tests against a condition would normally be in the condition section.
What are the downfalls to having a time trigger run at a given interval?
Really no downside other than it runs multiple times so you’d need to add in conditions to ignore it if it had already fired. but thats an entirely different automation in itself similar to cronjob rules
I’ll be honest. There are people on here that have better automation-fu than me. Someone out there has what you want, they just haven’t seen this topic yet.
You also have to understand that the automation isn’t constantly being checked. If the trigger is x or y it only checks when x or y occurs.
also an automation may run for 4 hours but only gets fired once when a specific condition is met.
After a while it starts to make sense, but not so much if you’re coming from anything other than jinja/yaml.