I created an automation that turns on a light if my wife or I am at home (by determining the location of the mobiles).
Although I used the trace tool, I still cannot make it work. I used the following example form Conditions - Home Assistant
condition:
alias: "Paulus home OR temperature below 20"
condition: or
conditions:
- condition: state
entity_id: "device_tracker.paulus"
state: "home"
- condition: numeric_state
entity_id: "sensor.temperature"
below: 20
And hereās my code:
condition:
alias: "Gime o Jose en casa"
condition: or
conditions:
- condition: device
device_id: TheId
domain: device_tracker
entity_id: device_tracker.samsung_s20fe
type: is_home
- condition: device
device_id: TheId
domain: device_tracker
entity_id: device_tracker.moto_g_8
type: is_home
But I canāt be certain a) as you are using device_idās (why ?) b) you seem to be mixing both device_idās and entity_idās (never seen that before.
You should really post the whole automation as itās difficult to check spacing with just a snippet
alias: Luces fondo
mode: single
max_exceeded: silent
trigger:
- platform: sun
event: sunset
condition:
alias: "Gime o Jose en casa"
condition: or
conditions:
- condition: state
entity_id: device_tracker.samsung_s20fe
state: 'home'
- condition: state
entity_id: device_tracker.moto_g_8
state: 'home'
action:
- service: switch.turn_on
entity_id: switch.luces_fondo
- delay: '03:00:00'
- service: switch.turn_off
entity_id: switch.luces_fondo
This is much shorter, easier to read and should do exactly the same thing
I would point out that (say) the sun sets at 19:03 and your wife comes home at 19:10 and you come home at 19:15 then the (background) lights will not come on, is that what you really want ?
Edit: AND (more importantly) wonāt go off when you expect them to (or at all if you put them on manually).
Yeah, but in that case youād just have an input_boolean (Vacation) that youād use throughout your Automations (another condition) to stop the ones you donāt want in āthat circumstanceā. (As opposed to groping around in the dark)
Edit: No, Iām being stupid. The whole point of this automation would be āif you were homeā.
Hence the : -
condition: or
conditions:
- condition: state
entity_id: device_tracker.samsung_s20fe
state: 'home'
- condition: state
entity_id: device_tracker.moto_g_8
state: 'home'
binary_sensor:
- platform: template
sensors:
## Luces Fondo
bs_luces_fondo:
value_template: >
{% set offtime = as_timestamp(state_attr('sun.sun', 'next_setting')) + timedelta(hours = 3) | timestamp_custom('%H:%M') %}
{% set time = states('sensor.time') %}
{% set pm = time >= '12:00' %}
{% set gimeencasa = is_state('device_tracker.samsung_s20fe', 'home') %}
{% set joseencasa = is_state('device_tracker.moto_g_8', 'home') %}
{% set sunbelow = is_state('sun.sun', 'below_horizon') %}
{{ pm and (time <= offtime) and sunbelow and (gimeencasa or joseencasa) }}
icon_template: "{{ 'mdi:lightbulb' if is_state('binary_sensor.bs_luces_fondo', 'on') else 'mdi:lightbulb-outline' }}"
friendly_name: Luces Fondo
automation:
## Luces Fondo Automation
- alias: au_luces_fondo
mode: single
max_exceeded: silent
trigger:
- platform: state
entity_id: binary_sensor.bs_luces_fondo
action:
- service_template: switch.turn_{{trigger.to_state.state}}
entity_id: switch.luces_fondo
This is a binary_sensor and an automation (they need to go in their respective locations for your setup).
The binary sensor checks that -
sun is below the horizon
the time is after 12:00 (noon)
that jose or gime are āhomeā
the time is before 3 hours after sunset
If all true the automation switches the light on else it is turned off (Manual Switching will overide this but the automation will ācatch-upā the next time it switches to the opposite state)
My issue with this is : -
a) it may tend to be an indicator to a burglar to show you are NOT at home
b) sunset at my location varies by 04:51:44 through the year (but thatās UTC variance, with DST itās more, so 05:51:44 (I hate DST) ) Thatās quite a variance so Iād probably replace the āofftimeā with a fixed time (say 22:00 ???) if so Then change āthisā to āthatā below : -
{% set offtime = as_timestamp(state_attr('sun.sun', 'next_setting')) + timedelta(hours = 3) | timestamp_custom('%H:%M') %}
{% set offtime = '22:00' %}
This is quite an advanced technique but it combines multiple states in an āeasy to readā way and creates a compact automation thatās about as efficient as you can get.
Edit: The above requires both sun.sun to be set up and ALSO the time and date sensors to provide (at least) sensor.time