Hassio combined with hard wired switches

Hi all,
I have a little riddle :slight_smile:

the current situation:
*i have a poolhouse with 8 electric cirquits (lightning and pool things). those connections are hard-wired with 24V buttons, connected to a pulse relay (teleruptor) who toggles on and off the 230V (one pulse on, next pulse off)

I now want to integrate this poolhouse into my existing hassio with the following conditions:
*the ā€˜analogā€™ system (wired buttons and teleruptors) need to stay. I want to be independent in case of IT problems :slight_smile:
*nevertheless, 90% of all the interactions will happen on the hassio and no longer on the buttons (see them as a fail-save)
*changing the wall-switch is also hard, because itā€™s nicely integrated.

I used already a tasmotised nodemcu (with a pulse timer of 50msec) and connected it in parallel with the existing wired system (on the inputs of the pulse relay). This works fine, butā€¦obvious the light icon on my hassio console lights op for 50 msec and goes to off again (mqtt based). this is visually annoying.

now iā€™m looking for two possible solutions:
*is there a simple (and cheap) way to ā€˜knowā€™ of measureā€™ the state of the electric cirquit (hassio has no idea of the wired button is pushed or not)
*if not, is there a way i can visually ā€˜cheatā€™ the lamp icon on hassio? meaning: one pulse it goes on, the next pulse it goes of and so on?

a very big thank you!

snippit of configuration.yaml:

light:
  - platform: mqtt
    name: "poolhouse1"
    command_topic: "cmnd/poolhouse/POWER1"
    state_topic: true
    qos: 0
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false
  - platform: mqtt
    name: "poolhouse2"
    state_topic: "stat/poolhouse/POWER2"
    command_topic: "cmnd/poolhouse/POWER2"
    qos: 0
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

As you have already played with some ESP stuff, you could consider putting a custom module on each 24V line.

You would need to monitor the 24V line for people pushing the button. Use a state machine to track the state. Tasmota, ESPurna, ESPEasy should, maybe with some modification or configuration allow this.

They would then maintain state machine and send HASS the current state on the correct state topic.

When HASS sends a state command the ESP devices then need to send the 24V pulse.

Remember of course that ESP devices are 3.3V and while they may tolerate 5V briefly, if you hit them with a full 24V pulse, while it may appear to work, the ESP will fry eventually. So you will need a voltage divider on the sense side, probably a 6:1 ratio. And either a 24V supply and mosfet or a boost converter on the sending side.

On your question on ā€œknowingā€ the state of the mains lines, there are plenty of sensors out there which you can add to the ESP which will give you a nice clean, safe 3.3V digital signal if the live line is energised. Some of them do not even need to tap the wire. Google for ā€œContactless mains sensor Arduinoā€ or similar. Without such a sensor you would risk the state HASS or ESP* has getting out of sync with reality. Something like this: https://www.instructables.com/id/Contactless-AC-Detector/

I have more or less a similar setup. I use sonoff ch4 pro to generate the pulses, and sonoff basics in parallel with the lights to see if they are on or off (in combination with template lights)

1 Like

hi, thanks for the response. i was also thinking that way, but the 3,3V is really a pain in the ***
this means, one way or another i need ANOTHER parallel cirquit on 5V of 3,3V to ā€˜measureā€™ the power.

stupid question, if decide to use the wired buttons as ā€˜backupā€™, can i cheat on my hassio interface to let the icon toggle on and of, indepenent of the real relay status?

hi, thanks for your response.
i donā€™t get the function of the sonoff basic. if you put in in parallel with the lights, how do you mean that?
can the sonoff basic ā€˜feelā€™ that there is power in itā€™s input? (i assume itā€™s also flashed?)

thanks for the potential great solution!

Most of the boards will take 5V input for power, but they regulate it to 3.3V. The chip itself will usually handle 5V on itā€™s pins, lots of people report sending it 5V and it works, but I donā€™t believe it makes any claims to be 5V tolerant.

If I understand correctly, you are reading a 24V line pulse. All you need to something like a 10K resistor and a 60K resistor to divide 24V down to 4V which is probably close enough. Google ā€œVoltage dividerā€ Actually 10K and 100K will get you close to 2V and thatā€™s enough for a logic HIGH on the ESP.

I believe what @francisp means is when the mains power is ON the SOnOff will be powered up, when the mains power is off the SOnOff will be powered off. You could then use it as a main power sensor. Quite an interesting hack.

Your correct. The sonoff basic has in tasmota the poweronstate set to switch on when they are powered on.

t   - platform: template
     lights:
       slaapkamervooraan:
         friendly_name: "slaapkamervooraan"
         value_template: >-
            {% if is_state('light.lichtslaapkamervooraan', 'on') %}
              on
            {% else %}
              off
            {% endif %}       
         turn_on: 
           service: switch.turn_on
           entity_id:  switch.sonoff2
           data:
             entity_id:  switch.sonoff2
         turn_off:
           service: script.scriptlichtslaapkamervooraanaf

  

both of you guys are wonderful. using a sonoff basic sounds like a foolproof and cheap way of monitoring (honestly i prefer it over a 5.5 cirquit, but the way of working stays the same).

4 dollars a piece ā€¦sounds like a good deal.
I will order some to do my testing. iā€™ll keep this thread updated.

a big thank you at Paul and at Francis (who is als speaking sutch according his snippits code :slight_smile: )

Any updates?

An idea is to use for latching relays a model like GEYA GRM8-02 ( see https://fr.aliexpress.com/item/32977619750.html ,look a the 4th photo) : if you shortcut the B1/B2 connexion, you have 2 outputs circuits . One can command your light/pump, the other one can provide a feedback to Hassio to know the state of the relay.

I just did a test with a ch4 and a sonoff powr216a (did not have a basic) and everything is working but when turning of the light it takes a while until ha is noticing the basic is offline to switch the status of the icon. I was wondering if in the example of francisp the script script.scriptlichtslaapkamervooraanaf contains some magic to overcome this issue?

my config is

light:
  - platform: template
    lights:
      staandelamp:
        friendly_name: "Staande Lamp"
        value_template: >-
            {% if is_state('switch.sonoff_powr216a', 'on') %}
              on
            {% else %}
              off
            {% endif %}    
        turn_on:
           service: light.turn_on
           entity_id: light.sonoff_salon
           data:
             entity_id: light.sonoff_salon
        turn_off:
           service: light.turn_on
           entity_id: light.sonoff_salon
           data:
             entity_id: light.sonoff_salon

thanks if you could answer this old topic.

First turns of the Sonoff basic, next switches of the sonoff4CH

  scriptlichtslaapkamervooraanaf:
    sequence:
      - condition: state
        entity_id: light.lichtslaapkamervooraan
        state: 'on'
      - service: light.turn_off
        data:
          entity_id:  light.lichtslaapkamervooraan
      - delay:
          # supports seconds, milliseconds, minutes, hours
          seconds: 1
      - service: switch.turn_on
        data:
          entity_id:  switch.sonoff2

Francis,
What about Eltako dimmers? Ok for the Sonoff Basic to capture the state of the light on or off, but how to find out the intensity of the light? And then changing the intensity via HA. Relay modules for dimmers arenā€™t easy to find.
Would like to keep current 24V Niko pulse switches working independent from HA.

I also have eltaco dimmers 24v, but use HA only for on off. Dimmers are not realy used in the last 10 years. Except if sombody else pressed to long on the button so I can set the light back to 100%. Would like to find some smart eltaco 24v sort of switches to replace de sonoff setup described above and eltaco with 1 device that works with my analoog Niko buttons and HA.