I have a device that monitors the level of a propane tank. The entity for the tank has a number of states associated with it, which includes (among others) the battery % for the monitor and the date/time of the last measurement. If I put the following in the template editor then I see their respective values:
{{ state_attr('sensor.neviweb130_sensor_lm4110_zb', 'Last_sampling_time')}}
{{ state_attr('sensor.neviweb130_sensor_lm4110_zb', 'Battery_level')}}
The output of the above shows something along these lines:
2024-01-18 20:58:19
100
I’d like to have the above displayed in an entity card in a dashboard, so I created a couple of template sensors to help accomplish this:
template:
- sensor:
- name: Propane Monitor Time of Last Check
state: >
{{ state_attr('sensor.neviweb130_sensor_lm4110_zb', 'Last_sampling_time') }}
device_class: timestamp
- name: Propane Monitor Battery Level
state: >
{{ state_attr('sensor.neviweb130_sensor_lm4110_zb', 'Battery_level') }}
device_class: battery
The battery level sensor appears to be working fine, but the date/time one always returns “unknown” no matter what I try. If I view the states in the Developer Tools it shows the date is in the format of “2024-01-18T20:58:19” which I believe is the correct format.
So how do I go about troubleshooting this? Am I not defining the template sensors properly?