I was able to integrate LOGO 8.4 with Home Assistant using MQTT successfully. I used https://www.youtube.com/watch?v=3QG-qFuS1cw as a guide.
I’ve added the below lines to my configuration:
mqtt:
sensor:
- name: "I1"
state_topic: "LOGO_Pub"
value_template: "{{ value_json['state']['reported']['I1']['value'][0] }}"
- name: "I2"
state_topic: "LOGO_Pub"
value_template: "{{ value_json['state']['reported']['I2']['value'][0] }}"
- name: "I3"
state_topic: "LOGO_Pub"
value_template: "{{ value_json['state']['reported']['I3']['value'][0] }}"
- name: "I4"
state_topic: "LOGO_Pub"
value_template: "{{ value_json['state']['reported']['I4']['value'][0] }}"
basically, it works, but I started getting errors in logs:
2024-10-24 11:21:59.260 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768864}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
2024-10-24 11:22:09.262 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768874}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
2024-10-24 11:22:19.263 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768884}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
2024-10-24 11:22:29.262 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768894}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
2024-10-24 11:22:39.261 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768904}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
2024-10-24 11:22:49.260 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768914}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
2024-10-24 11:22:59.261 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768924}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
2024-10-24 11:23:09.257 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768934}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
2024-10-24 11:23:19.257 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I2' (value: {"state":{"reported":{"$logotime":1729768944}}}, template: {{ value_json['state']['reported']['I2']['value'][0] }})
2024-10-24 11:23:19.261 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I3' (value: {"state":{"reported":{"$logotime":1729768944}}}, template: {{ value_json['state']['reported']['I3']['value'][0] }})
2024-10-24 11:23:19.262 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute 'I4' (value: {"state":{"reported":{"$logotime":1729768944}}}, template: {{ value_json['state']['reported']['I4']['value'][0] }})
The problem is that LOGO is sending the data to a single topic (this can’t be changed).
So when the value for I1 is changed, the state is sent to my topic, but all sensors try to get the value and three will throw errors (assuming I have 4 sensors)
Has anyone had a similar issue, when the same Topic is shared between multiple sensors?
Is there a way in value_template
to trigger value change when a specific JSON element is found?
EDIT:
I got a partial solution based on Adjusting template to obtain value from only one kind of MQTT message and ignore others - #2 by 123
mqtt:
sensor:
- name: "I1"
state_topic: "LOGO_Pub"
value_template: "{{ value_json.state.reported.I1.value[0] if value_json.state.reported.I1 is defined else this.state }}"
- name: "I2"
state_topic: "LOGO_Pub"
value_template: "{{ value_json.state.reported.I2.value[0] if value_json.state.reported.I2 is defined else this.state }}"
- name: "I3"
state_topic: "LOGO_Pub"
value_template: "{{ value_json.state.reported.I3.value[0] if value_json.state.reported.I3 is defined else this.state }}"
- name: "I4"
state_topic: "LOGO_Pub"
value_template: "{{ value_json.state.reported.I4.value[0] if value_json.state.reported.I4 is defined else this.state }}"
but now I get an error when I restart HA:
Rejestrator: homeassistant.components.mqtt.models
Źródło: components/mqtt/models.py:366
integracja: MQTT (dokumentacja, Problemy)
Pierwsze zdarzenie: 12:24:16 (2 zdarzenia)
Ostatnio zalogowany: 12:24:16
Exception raised while updating state of sensor.ai2, topic: 'LOGO_Pub' with payload: b'{"state":{"reported":{"$logotime":1729772603}}}'
Exception raised while updating state of sensor.ai1, topic: 'LOGO_Pub' with payload: b'{"state":{"reported":{"$logotime":1729772603}}}'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 657, in state
numerical_value = int(value)
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'unknown'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 660, in state
numerical_value = float(value)
^^^^^^^^^^^^
ValueError: could not convert string to float: 'unknown'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/models.py", line 366, in process_write_state_requests
entity.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1130, in _async_write_ha_state
self.__async_calculate_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1067, in __async_calculate_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1011, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 664, in state
raise ValueError(
ValueError: Sensor sensor.ai2 has device class 'None', state class 'None' unit 'V' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unknown' (<class 'str'>)
After restart all my sensors are unknown, so I’m not sure what else I must configure