logo elektroda
logo elektroda
X
logo elektroda

Raspberry, domoticz physical and remote switches, and GPIO pin extension

bplukaszbp 7767 12
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17464855
    bplukaszbp
    Level 10  
    Hello,

    There are many instructions on the network how to control the relay, let's turn on the lamp with domoticz and it actually works after configuration :) . My question is how do I add a doorbell switch to all of this? I do not know how to set the GPIO pin in domoticz as the input and connect it in the program so that the switch can be turned on both with the bell switch and remotely with domoticz.
    I will add that I want to use a raspberry to control lighting at home and this is where another question arises. There are too few GPIO pins in raspberry for me to use them as inputs and outputs for that lighting. Is it enough to buy an external extension of the GPIO pins to solve this problem and it will be possible to configure it so that in domoticz these pins are also visible, or do I need to connect it all, for example, under the arduinono mega (here there are enough pins and the control is currently working) and connect them with raspberry using mysensors? Let me add that I would prefer to omit the arduino entirely if it was possible ... Thanks in advance for your help.
  • ADVERTISEMENT
  • #2 17650477
    neo_84
    Level 15  
    I am looking for exactly the same everywhere a lot of information how to turn on the relay but from the domoticz panel. It would be a bit nonsense to go everywhere with a smartphone to turn on the light, and what if the battery dies?
    Has anyone solved this problem? how to configure it so that the lighting works remotely and via the button
  • ADVERTISEMENT
  • #3 17659042
    Arek1984
    Level 16  
    And isn't it better to use esp8266 to control the light and only have domoticz on rpi?
  • #4 17659524
    Slawek K.
    Level 35  
    You need some hardware to make it work via a button. I have it on esp8266 and more specifically on the Wemos D1 Mini. In the light switch box I have a self-produced module with esp and relay and an input for connecting the switch. I replaced the ordinary bistable switch with a monostable one (eg "Bell") and after giving the impulse, the state of the relay changes to the opposite, turning off and on the light, and at the same time I can also control it from the domotics. ESPEasy uploaded to esp8266.

    Greetings
  • ADVERTISEMENT
  • #5 17666935
    neo_84
    Level 15  
    Arek1984 wrote:
    And isn't it better to use esp8266 to control the light and only have domoticz on rpi?

    hmm sure and better On the other hand, to have 20 or more esp, does it not send a signal? all via wifi.
    The creators of domoticza made the program available for free, so you have to take what is. Maybe it's better to buy an arduino and expand the ports, but the question is whether it works with fakes ch340?
  • #6 17667477
    Slawek K.
    Level 35  
    [quote = "neo_84"]
    Arek1984 wrote:
    .... Maybe it's better to buy an arduino and expand the ports, but the question is whether it works with fakes ch340?

    How does this affect the operation of domotics? ch340 is pretty good chip, serial-> usb converter like any other.

    Pos
  • #7 17747050
    credens
    Level 10  
    My friend. You set yourself some GPIO as input by editing the file in the console:

    sudo nano /etc/init.d/domoticz.sh

    At the end you add e.g. for pin 27:

    
    /usr/bin/gpio export 27 in
    /usr/bin/gpio edge 27 both

    You restart Domoticz.

    Then in the panel you add the switch as 'Contact' and below in the list you select GPIO. If you correctly edited domoticz.sh, you should be able to choose pin 27 as INPUT. You add a device and by shorting the pin to 5V, the arrows on the screen should turn red (the reaction of the program works with a slight delay).
  • #8 18460879
    zbzu
    Level 9  
    I will hook to the topic, because I want to start the option of adding switches in Domoticz by activating the GPIO I / O and something is not working for me and I do not know why. I added these commands in the domoticz.sh file as it is given in this thread and when I want to activate the switch in domoticz, in the GPIO field I have the GPIO INIT ERROR message instead of the GPIO pin address to choose from. Anyone can tell what's wrong?
  • #9 18464653
    zbzu
    Level 9  
    I will answer myself because I have already fought the problem. Wiring that is uploaded is ver2.5 and the new Raspberry Pi 4 B raspberry requires uploading the 2.52 wiring version and then it works as it should.
    It may be useful to someone
  • ADVERTISEMENT
  • #10 18762331
    peete1978
    Level 9  
    Hello,

    I wanted to connect to the topic:

    I wanted to connect the lighting switch on the terrace with the domotic via WIFI and the MQTT protocol.
    I connected the usual bistable switch via sonoff mini (with the ESP Easy Mega v.20200328 soft loaded) according to the diagram.
    The problem is that it works from domotics, but the physical switch does not, how to fix it?

    In sonoff: I set GPIO 0 to the physical switch, and GPIO12 to the relay as below.
    Raspberry, domoticz physical and remote switches, and GPIO pin extension

    BUTTON:
    Raspberry, domoticz physical and remote switches, and GPIO pin extension

    RELAY:
    Raspberry, domoticz physical and remote switches, and GPIO pin extension

    DOMOTICZ:
    Raspberry, domoticz physical and remote switches, and GPIO pin extension


    Thanks in advance for your help
  • #11 18762405
    starob
    Level 29  
    Set BUTTON: IDX = 8 Send To Controler.

    With your settings, you send the switch state in vain.
    If that doesn't work, create a "dummy" switch and assign its index.
    Associate the "dummy" state with Taras

    The physical button should be "bell" because there will be times when you will have to switch it twice
  • #12 18770011
    peete1978
    Level 9  
    I made changes as posted but it didn't help.

    A friend helped me solve the mystery.

    The problem was the wrong assignment of the GPIO.
    After assigning the BUTTON to the GPIO4, the physical and domotic switch works.
    Raspberry, domoticz physical and remote switches, and GPIO pin extension
    Thanks for the help.
    best regards
  • #13 18775001
    peete1978
    Level 9  
    I have one more question about the switch, not related directly to the Raspberry, but more to the sonof and the switch itself.
    Namely, the switch from the Simon basic series with LED backlight works as it should, except ..... backlight (in the normal system, the backlight turns on when the light on the terrace is turned off, it goes out when it is turned on).
    I understand that at the moment the switch itself is not plugged into the 230v circuit, but only gives an impulse to the sonoff when turned on and off.
    I would like the visible backlight of the switch itself. During the day I will not know if the light is on on the terrace - and I would like to be able to judge it with one glance at the switch, the question is how to push it / bypass the problem so that the backlight in the switch works?
    Someone struggled with it and solved the problem.
    Thanks in advance for your help.

Topic summary

✨ The discussion revolves around integrating a doorbell switch with Domoticz on a Raspberry Pi for controlling lighting both remotely and via a physical switch. Users share various methods to configure GPIO pins as inputs in Domoticz, including editing the domoticz.sh file to set up GPIO pin states. Suggestions include using ESP8266 modules for relay control and the importance of proper GPIO assignments to ensure functionality. Issues with physical switches not working alongside Domoticz are addressed, with solutions involving correct GPIO configurations and the use of dummy switches. Additionally, users discuss the limitations of GPIO pins on Raspberry Pi and the potential for using Arduino for expanded control.
Generated by the language model.

FAQ

TL;DR: Update to wiringPi 2.52; it "works as it should". To fix physical+remote light control, use a monostable "bell" with ESP8266/ESPEasy or export GPIO inputs in Domoticz and link them to relays. [Elektroda, zbzu, post #18464653]

Why it matters: You keep wall switches usable without your phone while adding reliable smart control for lights.

Quick Facts

How do I add a doorbell-style switch so I can toggle lights locally and via Domoticz?

Use a monostable "bell" pushbutton with an ESP8266 module and a relay (e.g., Wemos D1 mini). Flash ESPEasy. Configure one GPIO as a button input and another for the relay. A button press toggles the relay locally, and Domoticz can also command it. This gives consistent local and remote control on the same circuit. [Elektroda, Slawek K., post #17659524]

How do I configure a Raspberry Pi GPIO as a Domoticz input?

  1. Edit /etc/init.d/domoticz.sh and add: /usr/bin/gpio export 27 in and /usr/bin/gpio edge 27 both.
  2. Restart Domoticz.
  3. In Domoticz, add a new switch as "Contact" and select GPIO 27 from the list. This exposes the pin as an input device you can use in automations or rules. [Elektroda, credens, post #17747050]

Why do I see "GPIO INIT ERROR" on Raspberry Pi 4?

Your GPIO layer is outdated. Raspberry Pi 4 B requires wiringPi 2.52 for Domoticz GPIO to initialize. Update wiringPi to 2.52, restart Domoticz, and the GPIO list appears. After the update, GPIO-based devices operate normally. "It works as it should" after applying the newer wiring. [Elektroda, zbzu, post #18464653]

My Sonoff Mini works from Domoticz, but the wall switch does nothing—what should I check?

Verify the BUTTON pin mapping in ESPEasy. Assign the BUTTON device to the correct GPIO. In one confirmed setup, mapping the BUTTON to GPIO4 fixed the physical switch. After that, both the wall switch and Domoticz controlled the relay correctly. [Elektroda, peete1978, post #18770011]

ESPEasy button changes don’t update Domoticz—how do I fix that?

Open the BUTTON device in ESPEasy. Set its IDX to your Domoticz switch ID and enable "Send to Controller". If it still fails, create a Domoticz Dummy switch and use that IDX. Use a monostable "bell" pushbutton to avoid state mismatches from bistable toggles. [Elektroda, starob, post #18762405]

Should I use a monostable "bell" or a regular bistable wall switch?

Use a monostable "bell" pushbutton. Each press sends a pulse, which cleanly toggles the relay and stays in sync with Domoticz. "The physical button should be 'bell'." Bistable switches can require double presses to resynchronize states after remote control. [Elektroda, starob, post #18762405]

Is distributing control to ESP8266 modules better than wiring everything to the Raspberry Pi?

Yes, many users prefer this. Put ESP8266-based nodes in switch boxes to handle the local button and relay. Keep Domoticz on the Raspberry Pi as the central controller. This reduces wiring complexity and scales well using Wi‑Fi and MQTT across rooms. [Elektroda, Arek1984, post #17659042]

Can I test a Raspberry Pi input by connecting it to 5 V?

No. The Raspberry Pi uses 3.3 V logic on its 40‑pin header. Driving a GPIO with 5 V can damage the SoC. Use 3.3 V levels and internal pull‑ups, or wire the switch to pull the pin to ground safely. Protect lines with series resistors if needed. [GPIO — Raspberry Pi Documentation]

How do I mirror a GPIO input to a relay in Domoticz?

Add the input as a "Contact" device using its GPIO. Control your light with a standard Domoticz switch. Then create a simple event to toggle the relay when the contact changes. This links the physical press to the relay while preserving app control. [Elektroda, credens, post #17747050]

Is a slight delay normal when I press the physical button?

Yes. The Domoticz UI can update with a slight delay after GPIO changes. This can arise from event handling or MQTT propagation. The input still triggers reliably, but the on‑screen indicator may lag briefly. [Elektroda, credens, post #17747050]

Do CH340-based Arduino boards cause issues with Domoticz?

No. The CH340 is a reliable USB‑to‑serial converter like other chips. It does not affect Domoticz operation. You can use CH340-based boards for serial bridges or integrations without concern. [Elektroda, Slawek K., post #17667477]

Why doesn’t my wall switch’s LED/neon backlight work with a Sonoff Mini input?

The Sonoff’s button input is a low‑voltage, isolated contact. Your backlight is a 230 V indicator, so it no longer gets power on that input. Options: replace the switch with a non‑lit pushbutton, add a separate mains indicator across the load, or rely on the app for status. [Elektroda, peete1978, post #18775001]
Generated by the language model.
ADVERTISEMENT