Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103366

MQTT sensor invalid timestamp format

$
0
0

Hi awesome folks.

I’ve had HomeAssistant monitoring my oil tank for a few years now, but in the last few releases I’m seeing log errors due to the rtl433 sensor timestamps not being properly formatted.

I have the rtl_433 add-on pulling data from the 433MHz receiver into MQTT, and then an MQTT sensor reading those messages.

My sensor is defined as:

    name: "Oil tank depth"
    state_topic: "rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664"
    value_template: "{{ value_json.depth_cm | int  }}"
    unit_of_measurement: "cm"

The MQTT payload includes:

% mosquitto_sub -h 172.21.230.50 -u [redacted] -P [redacted] -t "rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/#" -v
rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/depth_cm 58
rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/time 2022-05-08 20:18:35
rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/id 148218664
rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/flags 160
rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/maybetemp 17
rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/temperature_C 20.0
rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/binding_countdown 0

The exceptions look like this:

Exception in message_received when handling msg on 'rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/time': '2022-05-08 19:45:43' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 47, in wrapper msg_callback(msg) File "/usr/src/homeassistant/homeassistant/components/mqtt/sensor.py", line 283, in message_received self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 571, in _async_write_ha_state state = self._stringify_state(available) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in _stringify_state if (state := self.state) is None: File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 398, in state raise ValueError( ValueError: **Invalid datetime: sensor.oil_sonicsmart_148218664_utc provides state '2022-05-08 19:45:43', which is missing timezone information**

Is there a way for me to reformat the timestamp from the rtl_433 before it gets pushed to MQTT?
Is there a way to reformat the timestamp in the sensor template?

I couldn’t see anything on the templating page that made me understand how to access one field in my value template but alter the timestamp associated with that message before processing continues… Am I missing the bleeding’ obvious?

Cheers
Mike

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 103366

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>