Siemens logo 8

[SOLVED]----------------------------------------------------------------

I managed to understand how to configure home assistant via modbus to a siemens logo!
I have a 230V logo but the operation is the same on any siemens logo! that supports modbus TCP.
I’ll put my fully functional configuration below, hoping it can help someone.
I have a system that uses push buttons, not switches. But the operation is almost the same. For me who have push buttons, in LogoSoftComfort it is necessary to use the “current impulse relay” block indicated with the letters “RS”. And on the home assistant you have to create a script (I have yet to do it) that generates an impulse, or you use the very intelligent solution introduced by Moonlight_guest.
In practice I leave below the image of the LogoSoftComfort program and the code to put in the configuration.yaml file in the home assistant. In practice, the secret is to set Logo as a Modbus Server, as shown in this simple YouTube video. Doing so automatically activates a system that allows a modbus client (in this case Home Assistant) to read Logo’s digital Q outputs, without setting network output or other things. The addresses to read the coils are the following which I leave in the table below. ATTENTION: this is something that I discovered: some modbus clients start counting from 1 and some from 0. The Home Assistant modbus client starts counting from 0. So what you will find around is called in German “startadresse” in Home Assistant is equal to 0. I therefore load the table below, corrected for Home Assistant and for all those other modbus clients that start from 0 (such as the python library “pyModbusTCP” found at this link)
now it remains to understand how to control the inputs. Unfortunately as you read here you cannot directly control a coil (coil = output) which has been implemented as an output controlled by a physical button in LogoSoftComfort. This may seem counterintuitive, but it is not. If you read the link just mentioned it will show you why. So let’s understand how to control the exits. The secret is to create a virtual input which in turn controls the output, and this works.
Without messing up between memory of variables, registers, network inputs, network outputs, etc … you can simply create the “merker” block (maybe FLAGS in english… in italian I have written merker) indicated with the letter M and this will be a sort of input, but our Home Assistant will see it as a coil, which can be activated by a switch. Then we on Home Assistant will use the switch to activate the merker which will give a signal parallel to a physical input (using an OR) and activate / deactivate the digital output Q. Then automatically via always modbus a HA (home assistant) will occur update that will show the output on / off (a digital Q output translates to a binary_sensor in HA, look under my code).
ATTENTION: it depends on the version of your logo if you have the merker available. Look in the logo documentation, or in LogoSoftComfort by clicking on your logo in the list on the left and right clicking, properties, hardware type. There it is written if and how many flags you have. I have Logo! 8.FS4 230RCE 0BA0

Look at the addresses below for digital outputs and merker/flags from the table below

Now, this is the Logo SoftComfort (LSC) program
image

And this the configuration of configuration.yaml on HA:

That I report here as text so you can copy easy. If you are new to the HA world (like me) you can download FILE EDITOR from HA to edit the configuration.yaml


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml


modbus:
  name: hub1
  type: tcp
  host: 192.168.1.118
  port: 502
  
switch:
  - platform: modbus
    scan_interval: 1
    coils:
      - name: Switch1
        hub: hub1
        slave: 1
        coil: 8256
      - name: Switch1
        hub: hub1
        slave: 1
        coil: 8257




binary_sensor:
  - platform: modbus
    scan_interval: 1
    coils:
      - name: Q1
        hub: hub1
        slave: 1
        coil: 8192
        device_class: light
      - name: Q2
        hub: hub1
        slave: 1
        coil: 8193
        device_class: light
      - name: Q3
        hub: hub1
        slave: 1
        coil: 8194
        device_class: light
      - name: Q4
        hub: hub1
        slave: 1
        coil: 8195
        device_class: light
      - name: Q5
        hub: hub1
        slave: 1
        coil: 8196
        device_class: light

and so on…

if you want you can use the suggestion I have already mentioned to make a switch in HA (or even physical) behave like a push button. You can find it in this topic up here above

Personally, I want to set HA to give me a short boost, rather than keeping it as a switch.
So the next challenge is to figure out how to generate the impulse on HA, and then how to put that in the HA dashboard see the light bulb and that clicking on it turns on. For the moment I clearly see the binary sensor and the switch.
I keep you updated.
Thanks to everyone for helping me get here, especially at Viktors_Linovs and Moonlight_Guest and gliena

4 Likes

This config is fine except use the Logo program as Moonlight_Guest suggested and for the V10.0 and V10,1 adreses use coils 80 and 81 correspondingly.
Also I am not sure if binary sensor platform will work for you. Mine configuration.yaml looks like this for your case:

switch:
  - platform: modbus
    scan_interval: 1
    coils:
      - name: Sensor
        hub: hub1
        slave: 1
        coil: 80
      - name: Switch
        hub: hub1
        slave: 2
        coil: 81

In my setup I use binary sensor for lamps because that lamps are not dimmable and just have on/off state. I also use switch template to simplify control in Lovelace UI using Button card:

  - platform: template
    switches:
      basement_lamp:
        friendly_name: "Basement Left Lamp"
        icon_template: mdi:lightbulb
        value_template: "{{ is_state('binary_sensor.basement_lamp1', 'on') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.basement_lamp1
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.basement_lamp1

In LOGO I directly use S and R inputs for pulse relay for On and Off signals. Using Template Switch in HA allow to have the same state for switch and sensor .

1 Like

OK thanks. Then I was wrong to assign addresses.
In any case, what I wrote in the big post is correct and functional. In this regard I put here the update of my configuration.yaml and automations.yaml because in this updated configuration I have the buttons that if I click on the button, the button set the switch on for 300 milliseconds and then turn the switch back off.
beware that they are two separate files

automations.yaml

  - id: button1_auto
    trigger:
      platform: state
      entity_id: input_boolean.button1
    action:
      - service: switch.turn_on
        data:
          entity_id: switch.Switch1
      - delay:
          milliseconds: 300
      - service: switch.turn_off
        data:
          entity_id: switch.Switch1
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.button1


configuration.yaml


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml


modbus:
  - name: hub1
    type: tcp
    host: 192.168.1.118
    port: 502
  - name: hub2
    type: tcp
    host: 192.168.1.119
    port: 502


switch:
  - platform: modbus
    scan_interval: 1
    coils:
      - name: Switch1
        hub: hub1
        slave: 1
        coil: 8256
      - name: Switch2
        hub: hub1
        slave: 1
        coil: 8257
      - name: Switch3
        hub: hub1
        slave: 1
        coil: 8258
      - name: Switch101
        hub: hub2
        slave: 1
        coil: 8256
      - name: Switch102
        hub: hub2
        slave: 1
        coil: 8257


input_boolean:
    button1:


binary_sensor:
  - platform: modbus
    scan_interval: 1
    coils:
      - name: Q1
        hub: hub1
        slave: 1
        coil: 8192
        device_class: light
      - name: Q2
        hub: hub1
        slave: 1
        coil: 8193
        device_class: light
1 Like

very interesting!!! my idea was to always use Button card but take the status of the icon from the binary sensor and the action when clicked operate the corresponding button.

the purpose is identical to yours, but the path is different. I see if I can in my method otherwise I follow yours. Thanks

Another problem that I stumbled upon with this configuration is using google home to control lights that are grouped in one room. The problem is because we use template switch and switch.toggle to change the state of the virtual switch in hassio. So the issue becomes apparent when on the alreadu turned off switch you call action switch.turn_oiff. It will triger the template switch anyway and thus the light will turn on.

This happens when you use google home to control the hassio entity. Sometimes google home will call switch.turn_off command on already turned off entity which will lead that entity to turning on.
To prevent that instead of using switch.toggle, you should use script. I did one myself:

turn_light_on:
  sequence:
    - condition: template 
      value_template: "{{ is_state( template_device , 'off') }}"
    - service: switch.toggle
      data_template:
        entity_id: "{{ device }}"
turn_light_off:
  sequence:
    - condition: template 
      value_template: "{{ is_state( template_device , 'on') }}"
    - service: switch.toggle
      data_template:
        entity_id: "{{ device }}"

UPDATE:
I’ve got another solution without using the script:

      template_switch:
        friendly_name: Template switch
        value_template: "{{ is_state('binary_sensor.template_switch_sensor', 'on') }}"
        turn_on:
          - service_template: >
              {% if is_state('switch.template_switch', 'off') %} 
                switch.toggle
              {% else %}
                homeassistant.update_entity
              {% endif %}
            data:
              entity_id:
                switch.light
        turn_off:
          - service_template: >
              {% if is_state('switch.template_switch', 'on') %} 
                switch.toggle
              {% else %}
                homeassistant.update_entity
              {% endif %}
            data:
              entity_id:
                switch.light
1 Like

ok excellent thanks. I believe that to avoid this procedure it is necessary to do as Moonlight_Guest did.
Personally I used button-card which reads the binary sensor of the output and colors the icon accordingly, and if you click on the button-card it toggles the button corresponding to the input of that output, and I will follow your advice for google home

Even in that way google home would send switch.turn_on call on the entities that have stete ‘on’ and will try to trigger them accordingly, which sometimes does not correspond to the real situation.

Why not make it a light instead of using the button-card? Makes it all easier.

In configuration.yaml:

light:
  - platform: template 
    lights:
      office:
        friendly_name: "Office"
        value_template: "{{ states('binary_sensor.BinarySensorOfficeLight') }}"
        turn_on:
           - service: script.switch_on_off
             data_template:
               input_entity: switch.SwitchOffice1
        turn_off:
           - service: script.switch_on_off
             data_template:
               input_entity: switch.SwitchOffice2

I use 2 NI per lights on a RS switch with “on” on the set and off on “reset”. But never get any issues even with Google home. I was scared of the whole toggle thing…

thanks, I’ll try! I’m new to both home assistant and Logo, so any suggestions are well appreciated.
but the fact of my creation of the button toggle is to make the switch make an impulse and then go back off, so I am not forced to modify the logo program too much, since all the physical inputs that I have are buttons and not switches

Hi ALL,
This what I use on my Logo and HA:


image
I1 Is a momentary room switch
NI1 is a momentary room switch connected to another logo
NI2 is the signal from HA
Q1 is the light

The light status is read in HA by modbus:
image

The signal for switch on or off the light from HA to logo (NI2)
image

HA light
image

The automation for change state of the light
image

The automation for reset the switch on HA
image

What this script is doing? sending pulses?
I found a problem when I want to trigger multiple script instances at once. They do not work then.

Is your setup working when you turn on or off multiple lights at once? Because i had problem because of a script with delay.

what is the difference between using light and switch?

Not much but saves you a line of code if you do something like this:

icon_template: mdi:lightbulb

And before 0.107.0 you could turn easily all the lights off thanks to the light group. I have a script for that too.

I am a bit ashamed of my script it’s very messy…

switch_on_off:
  sequence:
  - service: switch.turn_on
    data_template:
      entity_id: '{{ input_entity }}'
  - service: switch.turn_off
    data_template:
      entity_id: '{{ input_entity }}'

it’s basically creating a pulse for each switch… Not very clean but was a good solution… I do it this way because as said before i don’t like the toggle and prefer to do a set and reset

I removed my script, as you made me realize that google would not work for groups and the reason is that the script cannot run for multiple switches at the same time. So I merged my code and it looks like this:

light:
  - platform: template 
    lights:
      office:
        friendly_name: "Office"
        value_template: "{{ states('binary_sensor.BinarySensorOfficeLight') }}"
        turn_on:
          - service: switch.turn_on
            data_template:
              entity_id: switch.SwitchOffice1
          - service: switch.turn_off
            data_template:
              entity_id: switch.SwitchOffice1
        turn_off:
          - service: switch.turn_on
            data_template:
              entity_id: switch.SwitchOffice2
          - service: switch.turn_off
            data_template:
              entity_id: switch.SwitchOffice2

Now i can turn off or on all the lights in my house with google

1 Like

Really impressed with all this work, but still can’t but wonder why Logo! ?
For a cost of one 4output PLC you can get 16/16 device which comes with MQTT etc?
Also, there are ESP devices with POE for much less, and they can do magic with ESPHome.
I like bot Logo and S7-1200 and use them for my machines, but for HA??? :slight_smile:

For me it’s simple I like the logo as a plc and it’s reliability for the heart of my house it was the most important thing. I feel I would not get this reliability with esphome. Knx is even more expensive so for me was a good compromise.

It’s a different hardware much better of an ESP and certificate for an industrial use

A question about the scan time, in my homeassistant configuration the scan interval is 1 second but really is 10 second, do you know about this difference?

The home assitant version is 0.97