having a bit of an issue with the order of states evaluations of my light entities.
Used to have âonâ, âoffâ, and âunavailableâ. Working perfectly for âyearsââŚ
now need to add an extra template operator because I first need to check if these lights are âreachableâ (hue lights with allow_unreachable: true)
this template does that:
state:
- operator: template
value: >
[[[
var id = entity.entity_id.split('.')[1] ;
var reachable = 'binary_sensor.' + id + '_reachable';
return states[reachable].state == 'off' ;
]]]
however, I need to put first in the order, since otherwise the âonâ and âoffâ styles are used first (remember these lights, though unreachable show âonâ and âoffâ as statesâŚI know filed an issue and PR/FR for that).
all going well except for the lights that donât have a binary_sensor.xxx_reachable because they are always online.
they either dont show up (an Ikea light) or show unavailable (a Hue light without binary_sensor)
This long story leads to 2 questions:
1- why doesnât the engine, when this template is evaluated to not being true, simply step to the next state/operator?
2- can I add a condition for the existence of the binary_sensor, to prevent it from being evaluated with an error
Ive tried things like:
- operator: template
value: >
[[[
var id = entity.entity_id.split('.')[1] ;
var reachable = 'binary_sensor.' + id + '_reachable';
if (reachable) return states[reachable].state == 'off' ;
]]]
but didnât have a lot of luck just yetâŚ
please have a look?
thanks!
update
experimenting with:
- operator: template
value: >
[[[
var id = entity.entity_id.split('.')[1] ;
var reachable = 'binary_sensor.' + id + '_reachable';
return states[reachable] && states[reachable].state == 'off' ;
]]]
now seems to work. Now have to wait until the night kicks in and my outside lights truly turn on and become reachableâŚ