How to update your Time and Date Template Sensors ready for Home Assistant version 0.115

11 Jan 2021

Supply

  • Home Assistant

I am glad to say that normal service has resumed as of update 0.117 and this method is no longer required. I have left the below update available for those who are running versions 0.115 to 0.117 and do not plan to upgrade anytime soon.

For those of you who have Template Sensors in Home Assistant which are Time or Date related may have noticed they haven’t been updating lately. Actually, if you are anything like me, you might not have noticed for a while as you have regularly been updating things and restarting the server. Either way Home Assistant have made a breaking change to the Template Sensor which is very easy to fix.

Previously, the Home Assistant Template Sensor required the entity_id: such as the below to be added to the sensor.

 
    - platform: template 
   sensors: 
     day_short: 
       value_template: "{{ ['Mon','Tues','Weds','Thurs','Fri','Sat','Sun'][now().weekday()] }}" 
       entity_id: sensor.time  

This use of the entity_id: line is no longer used or required in Home Assistant if you have updated beyond 0.115. 

Steps

1. Update Your Template Sensor YAML in Home Assistant

Moving forward the entity_id: will need to be added inside the template itself.

- platform: template 
   sensors: 
    day_short: 
    value_template: "{{ ['Mon','Tues','Weds','Thurs','Fri','Sat','Sun'][as_local(states.sensor.time.last_updated).weekday()] }}" 

As you can see above, we have replaced now() with as_local(states.sensor.time.last_updated) which will continue to automatically update the sensor.

Remember, you can test your updates and make sure they work by going to the Developer Tools section of Home Assistant.

2. More Template Sensor YAML Examples

{{ now() }} 

{{ as_local(states.sensor.time.last_updated) }} 

 

{{ as_timestamp( now()) }} 

{{ as_timestamp(states.sensor.time.last_updated) }} 

Would you like assistance with your own Home Automation setup? Whether you need help updating your Template Sensors in Home Assistant or whether you want to make your Home, Smart Home ready, contact us to see how we can help.

Home Automation Store

Why Proptimise ?

Tried and Tested

We only sell products which have been tried and tested by our team in our own installation.

Flexible Delivery

We offer a range of flexible delivery options including free delivery on orders over £95.

Multibuy Discounts

Look out for tiered discounts when purchasing bulk quantities of the same item.

Free Support

Need a helping hand getting started with your purchase? Get free setup support from our team.

×