Check if sensor already exists

Hi,

how can I avoid this error:

Jul 03 09:21:00 tower hass[11827]: ERROR:homeassistant.helpers.template:Error parsing value: list object has no element 1 (value: 'NoneType' object has no attribute 'registers', template: {{float(value.split ('=')[1]) / 60 / 24}})

The sensor is not yet available after startup because it gets filled by a script that calls data via ModBus. So I’ll need something like a “try catch” thingy.

- platform: command_line
  name: Filter change remaining time
  value_template: "{{float(value.split ('=')[1]) / 60 / 24}}"
  command: '/home/homeassistant/.homeassistant/helios/helios.py helios.fritz.box 10 v01033'

And, second question: how can I format the result to two decimals. Currently the value can get quite long based on the result of the division.

Thanks!

Can’t help with the loading error, but for the decimal you just have to use the round(n) function (n being the number of decimals).

So this should do the trick :

value_template: "{{float(value.split ('=')[1]) / 60 / 24 | round(2) }}"

2 Likes

That was too easy, thx :slight_smile: