Closed jmceara closed 2 years ago
Forgot to say: using version 2.1.0
Your json payload is
{
"battery":71,
"humidity":43.77,
"last_seen":"2022-05-18T14:25:08-03:00",
"linkquality":98,
"temperature":21.13,
"voltage":2900
}
MQTTSubscribe attempts to convert all incoming data to float. The easisest, if you don't care about last_seen
is to ignore it.
[[[zigbee2mqtt/Escritorio_-_Temperatura]]]
[[[[message]]]]
type = json
[[[[temperature]]]]
name = inTemp
[[[[last_seen]]]]
ignore = true
Alternately you could keep it as a string
[[[zigbee2mqtt/Escritorio_-_Temperatura]]]
[[[[message]]]]
type = json
[[[[temperature]]]]
name = inTemp
[[[[last_seen]]]]
conversion_type = none
Tks! I will try this tonorrow.
One sugestion is to parse only specified fields from condifuration. I mean, default state would be ignore and just include fields from condiguration.
Agree that if I was starting from scratch, 'opt in' woukd make sense. When I started I wanted everyting in the json and now with MQTTSubscribe 3 years old, I am hesitate to make that kind of breaking change. If one wants to 'opt in', you could do something like this.
[[[zigbee2mqtt/Escritorio_-_Temperatura]]]
ignore = true
[[[[message]]]]
type = json
[[[[temperature]]]]
name = inTemp
ignore = false
Are you all set?
Closing due to inactivity. Feel free to reopen if necessary.
Hi!
I have my weewx running for a while with MQTTSubscribe and individual mode. Now, I'm trying to use both Individual and JSON formats at the same time, but it's not working.....I don't think it's related to both modes, but something related to formatting.
This is what I'm getting in logs:
May 18 14:25:08 Skynet weewx[258144] DEBUG user.MQTTSubscribe: (Driver) MessageCallbackProvider data-> incoming topic: zigbee2mqtt/Escritorio_-_Temperatura, QOS: 0, retain: 0, payload: b'{"battery":71,"humidity":43.77,"last_seen":"2022-05-18T14:25:08-03:00","linkquality":98,"temperature":21.13,"voltage":2900}' May 18 14:25:08 Skynet weewx[258144] ERROR user.MQTTSubscribe: (Driver) MessageCallbackProvider on_message_json failed with <class 'user.MQTTSubscribe.ConversionError'> and reason Failed converting field last_seen with value 2022-05-18T14:25:08-03:00 using 'lambda x: to_float(x)' with reason could not convert string to float: '2022-05-18T14:25:08-03:00'.. May 18 14:25:08 Skynet weewx[258144] ERROR user.MQTTSubscribe: (Driver) **** MessageCallbackProvider Ignoring topic=zigbee2mqtt/Escritorio_-_Temperatura and payload=b'{"battery":71,"humidity":43.77,"last_seen":"2022-05-18T14:25:08-03:00","linkquality":98,"temperature":21.13,"voltage":2900}' May 18 14:25:08 Skynet weewx[258144] ERROR user.MQTTSubscribe: (Driver) **** MessageCallbackProvider Traceback (most recent call last):#012 File "/usr/share/weewx/user/MQTTSubscribe.py", line 1280, in _convert_value#012 return conversion_func['compiled'](value)#012 File "<string>", line 1, in <lambda>#012 File "/usr/share/weewx/weeutil/weeutil.py", line 1348, in to_float#012 return float(x) if x is not None else None#012ValueError: could not convert string to float: '2022-05-18T14:25:08-03:00'#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012 File "/usr/share/weewx/user/MQTTSubscribe.py", line 1463, in _on_message_json#012 (fieldname, value) = self._update_data(fields, fields_conversion_func, lookup_key, data_flattened[key], unit_system)#012 File "/usr/share/weewx/user/MQTTSubscribe.py", line 1247, in _update_data#012 value = self._convert_value(fields, default_field_conversion_func, orig_name, orig_value)#012 File "/usr/share/weewx/user/MQTTSubscribe.py", line 1285, in _convert_value#012 raise ConversionError("Failed converting field %s with value %s using '%s' with reason %s." \#012user.MQTTSubscribe.ConversionError: Failed converting field last_seen with value 2022-05-18T14:25:08-03:00 using 'lambda x: to_float(x)' with reason could not convert string to float: '2022-05-18T14:25:08-03:00'.
And this is my configuration:
All fields are working, except inTemp