I’m currently on 0.82.0. Not sure which version upgrade when they stopped working. Here is an example which stays “unknown” When I check its battery_level attribute, it reports “99”.
Can someone steer me in the right direction?
There was a breaking change with 0.81 re template sensors.
I don’t fully understand when (and when not) you have to include an entity_id in your config.
Looking forward to getting a little more explanation here now as well.
I got my worktime sensor back to work by inserting the entity_id as shown here:
- platform: template
sensors:
worktime:
friendly_name: WorkTime
entity_id: sensor.date_time
# worktime is Mon-Fri, starts at 08:00h and lasts until 16:59h
value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=8 and now().hour < 17 }}'
So, I assume by including entity_id: zwave.ecolink_motion_detector_2 it would work.
As @chairstacker says, the system can’t work out which entity to track because of your if statement.
I would also add that your if statement seems a convoluted way of doing this, the state_attr template extension is designed for this exact purpose, and also provides an entity_id to track…
@chairstacker - to answer your question, the template you’ve pasted contains no entities. Now() templates are only evaluated at that exact moment, so by adding the sensor.time as an entity_id to track, the system can reevaluate the template every time the time sensor changes (which is every minute, on the minute).
You could, for example, change that entity_id to your device tracker, and then it would only be reevaluated every time you move, or your living room light and it only be reevaluated when you turn them on/off. The actual output of the sensor is the same as it always was, but it only updates that value when the entity it is tracking changes state.
Thanks to both you and @chairstacker. I’ve made progress I think but it still doesn’t say 99%. Instead of saying unknown now, it says None %. Not sure if I have everything the way I should. Here is what I have:
It kinda should be in most circumstances, but it doesn’t have to.
The problem with using a different entity_id is that if the entity you actually want updates from is doing something weird when your template updates you’re going to get duff info, but using the same entity_id means it’s always in sync.
As per my first example though, in this case you shouldn’t need the entity_id line at all, because the entity_id to track is already in the template and is already unambiguous.
I’m going through each one of my zwave sensors and making the changes. I can’t just add the entity_id to fix it. It only works if I also change it to your code using state_attr. All this code worked a couple of weeks ago lol. I would never have figured that out on my on. Thanks again.
@anon43302295: Thanks a million for this–it works perfectly for me as well.
I’d add that the addition of device_class: battery under the definition also gives it a nice dynamic battery icon representing the actual charge state, too. It’s an easy change that adds a bit of polish. (Also not my own insight, but since I didn’t see it mentioned here, I figured I’d chime in.)