Siemens LOGO 8.4 MQTT

Greetings all,

First of all, appreciate the insights on this topic. I have received a Siemens LOGO 8.4 which is capable of MQTT. That LOGO 8.4 is communicating with other Siemens LOGO PLC’s on the network here which are controlling the actual relais.
The LOGO 8.4 is using network input and network outputs, which works as expected. I’m able to show the values, coming from 8.3 on the display of the LOGO 8.4.

I’ve registered LOGO 8.4 to the MQTT of Home Assistant(HA). Which is showing up in LOGO as registered.

Publish topic: LOGO_Pub
Subscribe topic: LOGO_Sub

Connection TCP

Also “cloud transfer values” are configured in LOGO.

When i use MQTT Explorer, which is connected to HA i see the values nicely getting towards HA.

LOGO_Pub
{"state":{"reported":{"M1":{"desc":"M-bit-1-1","value":[0]},"M2":{"desc":"M-bit-2-1","value":[0]},"M3":{"desc":"M-bit-3-1","value":[0]},"M4":{"desc":"M-bit-4-1","value":[0]},"V0":{"desc":"V-bit-0.0-1","value":[0]}}}}

LOGO_Sub is of course not visible, because that’s only visible when using a switch in HA to set value 0 in to 1 (on/off)

So far so good MQTT is getting towards HA. But i’m getting stuck in the configuration.yaml

mqtt:
  switch:
# Siemens LOGO 8.4 network switches
      unique_id: hottub-switch
      name: "Hottub"
      state_topic: "LOGO_Sub"
      command_topic: "LOGO_Sub/x.state.reported.V0.value[0]"
      payload_on: "1"
      payload_off: "0"
      optimistic: false
      qos: 0
      retain: false
      
  sensor:
# Siemens LOGO 8.4 sensors
    - name: "Pomp"
      state_topic: "LOGO_Pub"
      value_template: '{{ value_json.x.state.reported.M1.value[0] }}'
      unit_of_measurement: ''
      json_attributes_topic: "LOGO_Pub"
      json_attributes_template: '{{ value_json | tojson }}'
    - name: "UVC"
      state_topic: "LOGO_Pub"
      value_template: '{{ value_jsonx.state.reported.M2.value[0] }}'
      unit_of_measurement: ''
      json_attributes_topic: "LOGO_Pub"
      json_attributes_template: '{{ value_json | tojson }}'
    - name: "Sproeiers"
      state_topic: "LOGO_Pub"
      value_template: '{{ value_json.x.state.reported.M3.value[0] }}'
      unit_of_measurement: ''
      json_attributes_topic: "LOGO_Pub"
      json_attributes_template: '{{ value_json | tojson }}'


The values of the LOGO are configured as 0 or 1, but as you can see are in an array.

{"state":{"reported":{"M1":{"desc":"M-bit-1-1","value":[0]},"M2":{"desc":"M-bit-2-1","value":[0]},"M3":{"desc":"M-bit-3-1","value":[0]},"M4":{"desc":"M-bit-4-1","value":[0]},"V0":{"desc":"V-bit-0.0-1","value":[0]}}}}

And when M1 and M2 is 1 (on) i receive this:

{"state":{"reported":{"M1":{"desc":"M-bit-1-1","value":[1]},"M2":{"desc":"M-bit-2-1","value":[1]},"M3":{"desc":"M-bit-3-1","value":[0]},"M4":{"desc":"M-bit-4-1","value":[0]},"V0":{"desc":"V-bit-0.0-1","value":[0]}}}}

I spend a couple of hours trying to get the values out of it. Also with JSON Path finder trying different paths, but i can’t get the sensor nor the switch to work.

Anyone that can help me out on this? With regards to formatting of course in HA it would be nice to see on/off instead of 0/1.

It’s not clear (to me) in your post what is working and is not.
As a first, why all those .x in your sensors value template?

Hey,

Thanks for getting on this. Actually the only thing working are the Siemens LOGO’s and the transmit of MQTT data towards HA. HA is receiving the data. But i can’t get any values in the sensor, nor i can’t switch anything.

.x was a try based on JSON path finder.

Tried also M1.value[0] but same result, state remains “unknown” in HA.

You can use the template debugger to get your templates right, e.g.

{% set value_json = {"state":{"reported":{"M1":{"desc":"M-bit-1-1","value":[0]},"M2":{"desc":"M-bit-2-1","value":[0]},"M3":{"desc":"M-bit-3-1","value":[0]},"M4":{"desc":"M-bit-4-1","value":[0]},"V0":{"desc":"V-bit-0.0-1","value":[0]}}}} %}
{{ value_json.x.state.reported.M1.value[0] }}

gives

'dict object' has no attribute 'x'

OTOH, this works

{% set value_json = {"state":{"reported":{"M1":{"desc":"M-bit-1-1","value":[0]},"M2":{"desc":"M-bit-2-1","value":[0]},"M3":{"desc":"M-bit-3-1","value":[0]},"M4":{"desc":"M-bit-4-1","value":[0]},"V0":{"desc":"V-bit-0.0-1","value":[0]}}}} %}
{{ value_json.state.reported.M1.value[0] }}

To get “on”/“off/”, you need a binary_sensor,

mqtt:
  binary_sensor:
    - name: "Pomp"
      state_topic: "LOGO_Pub"
      value_template: '{{ value_json.state.reported.M1.value[0] }}'
      payload_on: '1'
      payload_off: '0'

Hi Chris,

Thanks for the insight. Good hint for the template debugger, din’t think of that one. (more familiar with LOGO then with HA). So thanks for helping on this.

the x was indeed the issue so now its reporting 0/1 or on/off depending on the sensor.

Will now focus on the switch, so send some MQTT back towards LOGO. Which is also complex, because the LOGO want’s to have the all elements back in the response which are in the publish.

{"state":{"reported":{"M1":{"desc":"M-bit-1-1","value":[0]},"M2":{"desc":"M-bit-2-1","value":[0]},"M3":{"desc":"M-bit-3-1","value":[0]},"M4":{"desc":"M-bit-4-1","value":[0]},"V0":{"desc":"V-bit-0.0-1","value":[0]}}}}

So that would be something like:

{"state":{"M1":{"value":[0]},"M2":{"value":[0]},"M3":{"value":[0]},"M4":{"value":[0]},"V0":{"value":[1]}}} 

#and to turn off

{"state":{"M1":{"value":[0]},"M2":{"value":[0]},"M3":{"value":[0]},"M4":{"value":[0]},"V0":{"value":[0]}}} 

Hey all,

I’m still trying, but publishing is difficult.

   unique_id: hottub-switch
      name: "Hottub"
      state_topic: "LOGO_Pub" # Topic to read the current state
      value_template: '{{ value_json.state.reported.M1.value[0] }}' # Gives me the status of the pump
      command_topic: "LOGO_Sub" # Topic to publish commands
      payload_on: "1"
      payload_off: "0"
      optimistic: false
      qos: 0
      retain: false

V0 can be 0 or 1. But i’m not getting it like the way LOGO! wants have it like
{“state”:{“M1”:{“value”:[0]},“M2”:{“value”:[0]},“M3”:{“value”:[0]},“M4”:{“value”:[0]},“V0”:{“value”:[0]}}}

The switch, like the sensor reports the correct state. But sending the payload like LOGO! needs, will i guess also require a payload_template?

What am i overlooking?