I have a couple of automations, one switches on the heating at specific times and the other switches it off if no one is home. I need to somehow combine them, so that if the heating was not triggered, as we were not home at the time, then it is triggered when we get home, if it is within the time it is supposed to be on. Here’s the relevant section of configuration.yaml
- id: '1573685276228'
alias: Thermostat on - Evening
description: ''
trigger:
- at: '17:30'
platform: time
condition: []
action:
- service: climate.turn_on
- id: '1573685325172'
alias: Thermostat off - Evening
description: ''
trigger:
- at: '23:00'
platform: time
condition: []
action:
- service: climate.turn_off
- id: '1574506627626'
alias: Not Home Thermostat
description: ''
trigger:
- entity_id: device_tracker.life360_me
from: home
platform: state
condition:
- condition: and
conditions:
- condition: template
value_template: '{{ not is_state(''device_tracker.life360_wife'', ''home'') }}'
action:
- service: climate.turn_off
@tom_l, I had thought of that, but I only want it to come on if it is within the time set by the timers. So in this example, I only want the tracker to switch on the heating if it’s between 17:30 and 23:00. I guess I can add a condition to every timer occurrence, but there are a number of them throughout the day so ideally I would like a global one.
Thanks again @tom_l. Can I combine or and and in a condition? For example, I have the following code to check whether either of us are in the house:
trigger:
- entity_id: device_tracker.life360_me
from: home
platform: state
condition:
- condition: and
conditions:
- condition: template
value_template: '{{ not is_state(''device_tracker.life360_wife'', ''home'') }}'
so would this look like:
alias: Thermostat on
trigger:
- platform: time
at: '06:30'
- platform: time
at: '12:30'
- platform: time
at: '17:30'
- platform: state
entity_id: device_tracker.life360_me
to: 'home'
condition:
- condition: state
entity_id: device_tracker.life360_me
state: 'home'
- condition: and
conditions:
- condition: template
value_template: '{{ not is_state(''device_tracker.life360_wife'', ''home'') }}'
- condition: or
conditions:
- condtion: time
after: '06:30:00'
before: '10:00:00'
- condtion: time
after: '12:30:00'
before: '14:00:00'
- condtion: time
after: '17:00:00'
before: '23:00:00'
action:
- service: climate.turn_on
entity_id: ?
I also notice that you have put a ? next to entity id for climate. This is missing in my configuration as I only have one climate entry. Does this matter?
Yes and no. If the service can’t find a valid entity id it will act on all the entities in the climate domain. In your case, just the one. It’s better if you do supply the entity rather than relying on a default fall-back like this. It’s unlikely but this behaviour could change in a future release and that could cause you an issue.
Now for the other question,
There are a couple of ways to do it. An automation is an interesting solution. I would have just put both trackers in a group. The group will be home if either of you are home.
Another way to do it is:
alias: Thermostat on
trigger:
- platform: time
at: '06:30:00'
- platform: time
at: '12:30:00'
- platform: time
at: '17:30:00'
- platform: state
entity_id: device_tracker.life360_me
to: 'home'
- platform: state
entity_id: device_tracker.life360_wife
to: 'home'
condition:
- condition: or
conditions:
- condition: state
entity_id: device_tracker.life360_me
state: 'home'
- condition: state
entity_id: device_tracker.life360_wife
state: 'home'
- condition: or
conditions:
- condtion: time
after: '06:30:00'
before: '10:00:00'
- condtion: time
after: '12:30:00'
before: '14:00:00'
- condtion: time
after: '17:00:00'
before: '23:00:00'
action:
- service: climate.turn_on
entity_id: ?
This will turn the heating on at the beginning of the specified times if either of you are home, or if you are both away and one of you comes home during the specified heating times.
Thanks, it turns out that I already use groups to my climate control, where I group several sensors to create an average. I just hadn’t realised that this could also be done with trackers. I’ve clearly got a lot to learn, but only been at this for a couple of weeks and have no previous experience of yaml. I must say that the community here is awesome, providing great support.
@tom_l is correct and I have to say ‘Well Spotted !’ (not sure I’ve got there anytime this side of next year)
BUT …
if you ever move to packages, then this will change again.
Not something you need to worry about now but I’m mentioning it so as if it crops up you may remember what the reason could be.
Edit: thinking about it you may not have an issue then either. I’m just weird as everything I have is in one package or another, no other files than ui-lovelace.yaml and a 25 line configuration.yaml
So in the above example, where it will turn the heating on at the beginning of the specified times if either of us are home, or if we are both away and one of us comes home during the specified heating times, if all conditions are met, the service is set to service: climate.turn_on.
If the conditions are met and the heating comes on, does this not need another automation to set service to climate.turn_off after the end times, i.e. after 10:00, 14:00 and 23:00?