If I understand you correctly, you want the binary sensor to be on if the action attribute of sensor.0x00158d0002b1136c_action is vibration, tilt or drop. If so, then:
Yeeeeesssss!!! It works!!!
Thanks a lot!!
I have another question, there is a way to lock in On for 10 seconds?
Because when the sensor is in vibration or other states after 1 second will turn to “” and i can’t see which sensor has triggered my alarm.
I use this in my notification:
{% for state in states.binary_sensor -%}\n {% if state.state == 'on' %}\n {{ state.name }}\n {%- endif -%}\n{%- endfor -%}\n"
Really thanks a lot i spent many days to make this working
Thanks a lot, but i don’t know why but won’t work anymore…
It seems that sometimes work just the first time i move the sensor but won’t turn on again if i move again the sensor and after reboot for just 1 time work but not every time…
Do you have some Idea?
My guess is one of the possible values reported by the device may be no value at all (empty string). While helping someone else with the same device, I learned it’s possible for it to return an action attribute with no value.
That may be. But that still should not cause an error. The state_attr() function specifically deals with those issues and will return None if the entity doesn’t exist, or the attribute doesn’t exist. Or even it they do both exist, and the value of the action attribute is an empty string, the template will evaluate to False, and the template binary sensor’s state will be off.
Take 2: If sensor.0x00158d0002b1136c_action doesn’t exist, or it doesn’t have an action attribute, or if the attribute’s value is an empty string, the template will still work. In any of these cases it will evaluate to False and the template binary sensor’s state will be set to off.
Which begs the question, What is this sensor: sensor.0x00158d0002b1136c_action'? If there’s the possibility it may be undefined at startup is it because it is slow to being automatically discovered or is it yet another Template Sensor?
Not sure that matters. Still not clear what “doesn’t work” means. Also the error mentioned seems to have to do with an automation, not this template binary sensory. Too many details missing at this point.
Thanks a lot!! Sorry for my late reply but I’m driving…
I’m not sure that the error of the template is related to what we have do…
So how can I search for more details?
Yes the sensor still in “” value and change for only 1 second to vibration or tilt ecc… and after that return to “”
This sensor use Zigbee2Mqtt to send the state information and after the system will boot it will take around 5 minutes to began ready to use
Maybe we should stick to the original intent of this topic, and that is the creation of the template binary sensor. When you are able, can you post your existing YAML code for it? Also, does it behave the way you want (which I believe is, when sensor.0x00158d0002b1136c_action's action attribute changes to one of the specified values, the binary sensor changes to on, and stays that way for at least 10 seconds)?
If the template binary sensor is behaving the way you wanted, then I think this topic is complete. If you’re having another issue, then you should start a new topic. If you do it would probably be good to provide a link back to this topic for reference.
I will post the code when I’m at home but I have added the same string that you have share to me…
The problem is that won’t work anymore…
If the sensor.0x00158d0002b1136c_action 's action is vibration or other the binary sensor still off… so won’t change…
I have also found this in the log
2019-10-01 19:23:55 WARNING (MainThread) [homeassistant.components.binary_sensor] Setup of platform template is taking over 10 seconds.