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"
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?
Hi @Taras - this is my confusion. I don’t have a sensor handling the timestamp - Perhaps it’s being manipulated inside the RTL_433 add-on as it passes the message to MQTT?
Reading between the lines are you suggesting I could/should create a sensor to handle the timestamp topic, and reformat that with | as_timestamp or similar?
Thanks @Taras. Was the MQTT payload I showed in the original post not what you’re after? I’m happy to try to get more granularity but not sure how best to get what you’re after, if it’s not as displayed by mosquito_sub?
E.g.
I’m trying that now, but I may have oversimplified my question and misled you…
I have two sensors defined, one reads out the depth in cm, but the other really does want to use a template as I’m converting from the depth to a volume:
Yup - as I suspected I’m still seeing the same ValueError. I’ll try commenting out the templated sensor and see if that clears it (with only the Oil tank depth sensor enabled).
Hmm. I looked again at the exception, which boils down to: sensor.oil_sonicsmart_148218664_utc provides state '2022-05-08 19:45:43', which is missing timezone information
But there’s no topic called utc in the MQTT payloads ,only time…
I wondered if this was a side-effect of the RTL_433 MQTT Auto Discovery add-on, but the script that this wraps explicitly ignores time as a field.
I can see the entity in my Dev Tools, distinct from the ones I’ve created in configuration.yaml:
Yup - errors are still being generated so this isn’t a templating problem, it’s an issue with rtl_433 / MQTT I think… although I’m no closer to understanding how to address it, do I disable the auto discovery and remove its entities (then report an issue to the maintainers)?
Exception in message_received when handling msg on 'rtl_433/74930c0d-rtl433/devices/CurrentCost-TX/3350/time': '2022-02-08 16:33:11'
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.currentcost_tx_3350_utc
provides state '2022-02-08 16:33:11',
which is missing timezone information
Exception in message_received when handling msg on 'rtl_433/74930c0d-rtl433/devices/Oil-SonicSmart/148218664/time': '2022-05-09 16:19:14'
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-09 16:19:14',
which is missing timezone information
Success! Disabling those other entities removed the error from the logs. Sorry for my misunderstanding / mis-statement of the problem, but thanks for the guidance @123.
I’ll see if I can report this in a more sane fashion to the RTL_433 folks.