For an index to all my stories click this text.
As you might know from previous stories on this weblog I have Domoticz installed as my home automation system. It was only getting slower and slower.
Now my idea was that the problem might lay in the fact that I was using a Raspberry Pi 2. And as I installed the latest updates, that could indeed slow down my system. So I considered upgrading to a Pi 3 or Pi 4.
And just for your information: If you want to install Domoticz you will need at least a Pi3 as previous versions are no longer able to install Domoticz.
Clicking on the Devices Tab in the settings menu stopped the complete system for several minutes.
Then I noticed something.
Each page of the devices pages contains 100 entries (you can select that). And I had no less then 225 pages. That means that the database had 22500 entries. 
And many of these entries were from years ago. As you can see the highest page numbers pointed to database entries from 2016. That is 7 year ago, at the time of this writing !!!
Why on earth would I want to keep that information. More even while the entries hold info on switches, thermometers etc from neighbours. And that that does not interest me.
So at the top of the page I clicked on the button that says Ongebruikt. The English version will mention Unused.
Next I clicked on the small V at the top. After two clicks all entries on that page were selected. Then I clicked on the waste basket next to the V and the entries from that page disappeared.
Make sure you use the Unused entries button otherwise you might remove your own settings !!!!
I removed all unused entries that way and this made Domoticz fast again !!!
So no need to switch to a more modern Raspberry Pi or even another home automation system !!!
Please be aware that Domotics keeps receiving and storing data from all kinds of switches and thermometers all the time. So a regular cleanup is advised.
Maybe it's me, but I could not find this simple speed improvement in the manual, so I did not want to keep it from you.
Till next time
have fun
Luc Volders
Friday, March 14, 2025
Speeding up Domoticz
Friday, November 10, 2023
Domoticz with MicroPython part 3
For an index to all my stories click this text.
This is the third story in a series about sending data to, and receiving data from Domoticz with MicroPython.
The reason why I am writing these is because I migrated to a new internet provider. That meant reprogramming all of my microcontrollers. They needed to contact my new router and got new IP addresses. It was a hell of a job.
So I decided to reprogram the sensors in MicroPython. What made this easy is that all my favorite microcontrollers (ESP8266, ESP32 and Raspberry Pi Pico) are supported by MicroPython.
The first story describes connecting a pushbutton to a Raspberry Pi Pico and sending it's data to Domoticz. You can use this for a myriad of purposes like a doorcontact, a windowcontact, doorbell, PIR, vibration sensor, rain sensor etc. etc. Another purpose is using your Pico with a pushbutton as a remote control for your lamps. You can re-read that story here:
http://lucstechblog.blogspot.com/2023/11/domoticz-with-micropython-part-1.html
The second story describes how to build a switch in Domoticz that will set a led, attached to a microcontroller, on or off. You can re-read that story here:
http://lucstechblog.blogspot.com/2023/11/domoticz-with-micropython-part-2.html
In this story I am going to describe how we can send data from a microcontroller to Domoticz. The first story did the same but that was only an on or off signal. This time I am going to send values to Domoticz.
Again there are many purposes for this. Think temperature values from a digital thermometer, light intensity from an LDR, a fans rotation speed, measured distance from an ultrasonic sensor, water level from a tank etc.etc.
Breadboard setup
Actually it is the same setup from the first story. Just a Raspberry Pi pico with a pushbutton.
Nothing special here. The pushbutton is attached to GPIO14 and a 10K pull-up resistor is used. This is the same setup I used in the first story.
Please note that you can also use an ESP8266 or an ESP32 in stead of the Pico. Just alter the pin number where the button is attached to in the program.
What we are going to do.
For sending data from MicroPython to Domoticz we are gfoing to use the urequests library. This is the same library as we used in the first story and it is incorporated in the standard MicroPython distribution. So nothing to doenload.
As said you can use that for a myriad of sensors. For the sake of this example we are going to use a random value between 10 and 20. These values are used to simulate a thermometer.
The program will wait till you press a button and when you do a random value is send to Domoticz.
Domoticz will put this value in a simulated thermometer.
Creating a thermometer in Domoticz
In Domoticz coose the Setup tab and then the Hardware Entry. In the Name field fill in Virtual 1 and as type chose Dummy from the drop-down list. Then press the Add button.
A new entry will be made in your hardware list. It has the name Virtual 1 which you gave it.
Now click on Create Virtual Sensor.
I gave the virtual sensor the name MicroPython-test-thermometer and as type I chose Temperature from the drop down menu.
As you can see there are loads of options for sensors. I urge you to experiment a bit by choosing different sensors as Temperature later on. For now leave it as Temperature.
Press the OK button and Domotica will tell you that the sensor can be found in the devices tab. But don't bother.
The just created thermometer is immediately visible in the Temperature tab. As you can see I already had an outside thermometer. The MicroPython test thermometer says it is 0 degrees and that is because it has no data received yet.
To send data to this virtual thermometer we need to now it's ID (IDx) and that is easy to find. 
Just press the edit button on your just created thermometer and there it is: Idx 23656
Your Idx number will definitely be different. Just note it down cause we are going to need this.
Domoticz API
To send data to Domoticz we can use it's API. You can find the API's documentation here:
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
Now look for the section: 10 Update devices/sensors and especially at section 10.2 Temperature
/json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=TEMP
This is the command that Domoticz needs to set the thermometers value.
We just need to precede that by our Domoticz IP address. Alter the IDX in our just found Idx. And we need to replace TEMP by the temperature value.
The thermometers value says at this moment 0 degrees as the picture above shows.
To test if we did everything right, until now, paste the required API call into your browsers URL bar.
192.168.178.68:8080/json.htm?type=command¶m=udevice&idx=23656&nvalue=0&svalue=18
This is my version.
My Domoticz has IP address 192.168.178.68:8080 in my network.
The thermometers ID is 23656
And I want to set the thermometer at 18 degrees.
And there you go. The browser send the data to Domoticz and the temperature was updated.
The only thing we have to do now, is to translate this API into a MicroPython program.
The MicroPython program.
This program actually is very similar to the program from the first story. We need Urequests to send data to Domoticz. And I added the random library (which is included with MicroPython) to generate a random number.
import random import machine import network import urequests as requests import gc import time button1 = machine.Pin(14, machine.Pin.IN) ssid = "YOUR-ROUTERS-NAME" pw = "PASSWORD" wifi = network.WLAN(network.STA_IF) wifi.active(True) wifi.connect(ssid, pw) print('Waiting for connection.',end="") while wifi.isconnected() == False: time.sleep(1) print('', end='.') print("") ip = wifi.ifconfig()[0] print("Connected with IP adress : "+ip) while True: if button1.value() == 0: randval = random.randint(10,20) sendtemp = ("http://192.168.178.68:8080/json.htm?type=command¶m=udevice&idx=23656&nvalue=0&svalue=") requests.get(sendtemp + str(randval)) time.sleep(1) gc.collect()
This should pose no difficulties.
import random import machine import network import urequests as requests import gc import time button1 = machine.Pin(14, machine.Pin.IN)
The program starts with importing all necessary libraries and then defines GPIO14 as an input pin. This is the pin where the button is attached to.
ssid = "YOUR-ROUTERS-NAME" pw = "PASSWORD" wifi = network.WLAN(network.STA_IF) wifi.active(True) wifi.connect(ssid, pw) print('Waiting for connection.',end="") while wifi.isconnected() == False: time.sleep(1) print('', end='.') print("") ip = wifi.ifconfig()[0] print("Connected with IP adress : "+ip)
This is the standard way to make a connection with your router. Do not forget to replace YOUR-ROUTERS-NAME and PASSWORD with your routers credentials.
The program tries to make a connection with the router and as long as that is not established a dot will be printed in Thonny's shell.
When te connection is made the microcontrollers IP address is printed in the shell.
while True: if button1.value() == 0: randval = random.randint(10,20) sendtemp = ("http://192.168.178.68:8080/json.htm?type=command¶m=udevice&idx=23656&nvalue=0&svalue=") requests.get(sendtemp + str(randval)) time.sleep(1) gc.collect()
This is where it all happens. The program waits till a button is pressed. If that happens a random value between 10 and 20 is created and put in the randval variable. Next a string with the name sendtemp is created which has the main part of the API call. The only thing that is missing is the value we want to send.
That value is created in the next line where it is added to sendstring. Please notice that the random function creates an integer value which is made into a string with the str() command.
Make sure you replace the Idx value I used with your own value.
urequests clogs up some memory. And that memory needs to be freed again otherwise we might run into "out of memory" problems. That is where the Garbage collect library comes in. gc.collect() frees up any unused memory.
That is all.
Now repeatedly press the button attached to your Microcontroller and watch the value in Domoticz change.

Expansion
Nobody is keeping you from sending a value to multiple entries in Domoticz. For testing purposes I used the thermometer I created and created an extra sensor display with the type Custom Sensor.
That second sensor display got 23776 as it's Idx.
I just had to add 2 lines in the while loop:
while True: if button1.value() == 0: randval = random.randint(10,20) sendtemp = ("http://192.168.178.68:8080/json.htm?type=command¶m=udevice&idx=23656&nvalue=0&svalue=") requests.get(sendtemp + str(randval)) time.sleep(1) sendval = ("http://192.168.178.68:8080/json.htm?type=command¶m=udevice&idx=23776&nvalue=0&svalue=") requests.get(sendval + str(randval)) time.sleep(1) gc.collect()
And I had two sensor displays. The thermometer was in the Temperature tab and the custom sensor in the Utility tab.

Of course they got the same value because I only generated 1 random value and send that same value twice to Domoticz.
This is only an illustration to show that you can attach multiple sensors to the same microcontroller and send all values to domoticz.
Just experiment with this and I am sure you can come up with some clever solutions for your home automation.
MicroPython ???
For those that have no experience with MicroPyton and want to learn the languages and how to use it with a Raspberry Pi Pico I can recommend two books I wrote on this subject and which you can find a link for at the bottom of this story.
And do have a look at my new website that is tjokfull with tips for programming in MicroPython:
https://micropython-tips.weebly.com/
Till next time
Have fun
Luc Volders
Wednesday, November 8, 2023
Domoticz with MicroPython part 2
For an index to all my stories click this text.
This is the second story in a series about sending data to and receiving data from Domoticz with MicroPython.
The reason why I am writing these is because I migrated to a new internet provider. That meant reprogramming all of my microcontrollers. They needed to contact my new router and got new IP addresses. It was a hell of a job.
So I decided to reprogram the sensors in MicroPython. What made this easy is that all my favorite microcontrollers (ESP8266, ESP32 and Raspberry Pi Pico) are supported by MicroPython.
The first story describes connecting a pushbutton to a Raspberry Pi Pico and sending it's data to Domoticz. You can use this for a myriad of purposes like a doorcontact, a windowcontact, doorbell, PIR, vibration sensor, rain sensor etc. etc. Another purpose is using your Pico with a pushbutton as a remote control for your lamps. You can re-read that story here:
http://lucstechblog.blogspot.com/2023/11/domoticz-with-micropython-part-1.html
This time we are going to do the opposite. We are going to attach a led to a Raspberry Pi Pico W and use a button on the Domoticz screen to set that led on or off. You can easily adapt this to an ESP8266 or ESP32 by just altering the pin number for the pin where the led is attached to.
This can also be used for many purposes. Think of setting a lamp on or of, starting/stopping a fan, opening a garage door, starting a pump, opening blinds etc etc etc.
Breadboard setup
For testing I attached a led to GPIO15 of the Pico
Nothing special in this setup. Just a led connected to GPIO15 and a 220 Ohm power delimiting resistor.
In a real world situation you would replace the led by an array to switch real lamps, a motor, or a fan etc. on or off.
You could even use the same setup from last story and add the led.
And like stated above you can easily adapt this to exchange the Raspberry Pi pico for an ESP8266 or ESP32. Just change the pin number accordingly in the program.
Sending data from Domoticz to the Pico
We have to have a way to make the microcontroller receive data from Domoticz. The easiest way to do this is to use the webserver framework. Normally we create a webserver in MicroPython and that sends or receives data from a computer or microcontroller. The webserver then presents a webpage on which that data is displayed.
We are going to use the webserver software but we are not going to build a webpage. We are only using that software to receive data from Domoticz and act on the received data.
Domoticz switch.
We need a switch in Domoticz that we can click to send data to the microcontroller. If you are just as lazy as I am you can use the same switch we used in the previous story. So look at : http://lucstechblog.blogspot.com/2023/11/domoticz-with-micropython-part-1.html
And follow the steps to build a virtual switch.
I will summarise the steps here:
- In the setup menu choose hardware
- Add a new device. Give it the name Virtual 1 and choose as type Dummy (Does nothing, use for virtual switches only)
- Click in the new entry Virtual 1 on Create Virtual Sensors
- In the pop-up menu give it the name MicroPython-test-switch and choose "Switch" as sensor type.
- Click on OK
- Move over to the Switches tab at the top of the screen.
- You can find the new switch there. Click on the edit button.
- Click on the switch Icon and make sure to use Generic

Your new switch will look like this.
The MicroPython program.
The program is like stated above the framework for a webserver. But I left out all the HTML code. So the only thing this does is acting on incoming signals.
Here is the full code:
import network import socket import time from machine import Pin led = Pin(15, Pin.OUT) ssid = "YOUR-ROUTERS-NAME" pw = "PASSWORD" wifi = network.WLAN(network.STA_IF) wifi.active(True) wifi.connect(ssid, pw) print('Waiting for connection.',end="") while wifi.isconnected() == False: time.sleep(1) print('', end='.') print("") ip = wifi.ifconfig()[0] print("Connected with IP adress : "+ip) addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] s = socket.socket() s.bind(addr) s.listen(1) while True: cl, addr = s.accept() print('client connected from', addr) request = cl.recv(1024) print(request) request = str(request) led_on = request.find('testlamp-on') led_off = request.find('testlamp-off') if led_on == 7: print("led on") led.value(1) if led_off == 7: print("led off") led.value(0) cl.close()
Most of this will be familiar to those who have worked with MicroPython before. Nevertheless I will go over the details.
import network import socket import time from machine import Pin led = Pin(15, Pin.OUT)
First things the program does is importing the necessary libraries. These are all included with your standard MicroPython distribution.
As you have seen on the breadboard layout above, the led is attached to GPIO15.
ssid = "YOUR-ROUTERS-NAME" pw = "PASSWORD" wifi = network.WLAN(network.STA_IF) wifi.active(True) wifi.connect(ssid, pw) print('Waiting for connection.',end="") while wifi.isconnected() == False: time.sleep(1) print('', end='.') print("") ip = wifi.ifconfig()[0] print("Connected with IP adress : "+ip)
Make sure you replace "YOUR-ROUTERS-NAME" and "PASSWORD" with your own routers credentials.
The next lines make sure the microcontroller (Pico or ESP) connects to your router. It first prints "Waiting for a connection "and prints every second a dot (".") as long as there is no connection made.

When the connection to your router has been established the program will print your microcontrollers IP-address in Thonny's shell.
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1] s = socket.socket() s.bind(addr) s.listen(1)
The program then opens a websocket. That is a connection through which we can send commands and data to the microcontroller.
while True: cl, addr = s.accept() print('client connected from', addr) request = cl.recv(1024) print(request)
Here starts an endless loop. The program waits any data coming in. When there is anything received that is printed in Thonny's shell so we can see what data is received.
request = str(request) led_on = request.find('testlamp-on') led_off = request.find('testlamp-off')
The received data is tested for some specific words. I used the words:
testlamp-on
testlamp-off
These are the words that Domoticz needs to send to the microcontroller to set the led on or off. You can change them in anything you like. Just make sure to note them down as we need to use them in Domoticz later on.
if led_on == 7: print("led on") led.value(1) if led_off == 7: print("led off") led.value(0)
The comands in the previous section: led_on = request.find('testlamp-on') searches for the words "testlamp-on" and finds at what position in the received data these words where found.
If these words are found, they are found at position 7 in the received data. This means the words "testlamp-on" or "testlamp-off" start at the 7th letter in the received data.
So if these words are found at that position the lamp is set on or off.
cl.close()
And this last command closes the connection. The while True loop starts over looking for a new connection.
Setting the led on or off from the browser.
As Domoticz is just sending a HTTP command and we can test if it works from our browser.
Start with the IP-address of the microcontroller which was printed in Thonny's shell. In my case that was 192.168.178.193 and let that follow by "/testlamp-on"
So the complete command is:
http://192.168.178.193/testlamp-on

Put that in your browsers address field and the lamp should go on.
http://192.168.178.193/testlamp-off
Should put the lamp off again.
Test if this works. If it does not check the code again, and check that the led was connected in the right way. Also make sure you use the right IP address.
Thonny's shell will show the following:

You can see the IP address from the client that connected to the microcontroller. In this example that IP address is 192.168.178.196 which is the IP-address from my computer.
The second line says:
b'GET /testlamp-on HTTP
And this shows that the text "testlamp-on" is indeed at the 7th position. which makes the webserver software set the led on.
Back to Domoticz
Now we know that the webserver works as expected we can make Domoticz send these commands.

Press on the edit button in your switches entry.

Fill in the commands:
http://192.168.178.193/testlamp-on
http://192.168.178.193/testlamp-off
In the fields On Action and Off action.
Do not forget to press the Save button.
And that is it.
Pressing the switch in Domoticz should turn the led on or off.
In the real world.
Setting a led on or off from your Domoticz home automation system is fun but not really related to the real world.
So exchange the led for a relay and you can control real lights, fan's, pumps, ledstrips, garden sprinklers and whatever more you might think off.
If you use this setup and the one from the previous story on a second controller you can push the pushbutton on the first controller and have that set the lamp on, on the second controller.
This way you can have a lamp automatically go on if a pir detects motion, or a door contact is made etc.
Another option would be changing the pushbutton from the previous story into an LDR. As soon as the sun rises have the second Pico lower the sun screens or blinds.
The possibilities are limited by your imagination.
So have fun
Till next time
Luc Volders
Friday, November 3, 2023
Domoticz with MicroPython part 1
For an index to all my stories click this text.
I migrated to a new internet provider. That meant reprogramming all my microcontrollers. They all needed to contact my new router and got new IP addresses. It was a hell of a job.
To achieve this I needed physical contact with those micro's to connect them to my PC. But what annoyed me most was that I needed to search all the programs that were on these micro's (yes, I am not the best organised) and recompile them in the Arduino IDE (C++) which is slow.
Interlude.
Actually I did not need to make physical contact with all of my microcontrollers cause some of them are running ESPEasy. I am doing a series on ESPEasy and you should really check it out. ESP8266 and ESP32 microcontrollers that are programmed with ESPEasy can be reprogrammed over wify !!! No need to attach an USB cable. There isn't even much programming at hand with ESPEasy. But that also takes a lot of fun out of puzzling to get things working.
MicroPython is an interpreted language which means that it is slower in processing data. But my projects are not time critical. I have no fast rotating motors that I need to know the rotation speed from etc. I just have temperature sensors, light switches a doorbell etc. Nothing MicroPython is not perfectly capable of handling.
Next to that I just have to plug the microcontroller into my PC through USB and I can download the program from the controller itself. No more searching for the programs anymore !!
So I decided to reprogram the sensors in MicroPython. What made this easy is that all my favorite microcontrollers (ESP8266, ESP32 and Raspberry Pi Pico) are supported by MicroPython.
Domoticz is still my preferred home automation system. So I had to program 4 different ways of communication with Domoticz:
- Send data from a simple switch like a doorcontact, windowcontact, doorbell, PIR, vibration sensor etc. to Domoticz
- Send a signal from Domoticz to a microcontroller to set on/off a relay or a lamp etc.
- Send a value (like thermometer value etc) to Domoticz
- Set a slider in Domoticz and send it's data to a microcontroller for dimming lamps, changing a fans speed etc. etc.
I this and the next stories am going to show you how I did these in MicroPython.
Send a button's data to Domoticz
Look upon the word button in a broad context. It could be a pushbutton connected to your microcontroller, a door contact, a doorbell, a PIR, a tilt sensor, a vibration sensor, a rain sensor etc. etc. etc.
For this example I am using a Raspberry Pi Pico W with a pushbutton connected to GPIO14.
Step 1: Create a virtual device
In the Setup tab chose Hardware and add a new device. I gave it the name Virtual 1 and choose as type Dummy. Then push the blue Add button
Click now on the newly created Virtual 1 entry and click on Create Virtual Sensors.
I gave my new switch the name MicroPython test switch and chose Switch from the drop down menu as Sensor Type. A message appears that the new sensor is created and can be found in the Devices entry in the Setup tab. 
There is no need to look in the Devices entry as the new switch is readily available in the switches section. 
Click on the edit button of the switch.
The default icon is a lamp. I changed this into Generic which is a switch..
There are two important things on this page.
First at the top you see the IDX which in this case is 23637. You will need this number for using in the MicroPython program. Your own Domotic will give you of course a different number.
Second (but obvious) you need to press the Save button at the bottom.
That is it. The button is defined.
There is however one extra feature. As soon as you press the save button the Switch Type menu changes from nothing to On/Off.
You can now change this into another type of sensor like you can see in this list. Choosing another type also changes the icon. Leave it for now as it was.
Step 2: the MicroPython program.
First thing is that we need to know how we can send information from MicroPython (or another language) to Domoticz. And we will use the Domoticz API for that.
You can find the Api's at:
https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
On that page look for the Lights and Switches section (section 4) and then look at 4.2 Turn a light/switch on/off
/json.htm?type=command¶m=switchlight&idx=99&switchcmd=<On|Off|Toggle|Stop>
This is the general API call for setting a switch on or off. This has to get preceeded by the IP address of Domoticz. In my setup Domoticz has the IP address: http://192.168.178.68:8080
There are three possiblities. We can give the command to set the switch:
- On
- Off
- Toggle
In this example I have attached one button to the Raspberry Pi Pico W. So we use that same button to set the switch on or off. Therefore we use the Toggle command.
The complete API call therefore is:
http://192.168.178.68:8080/json.htm?type=command¶m=switchlight&idx=99&switchcmd=Toggle.
Please make sure that you use the right IP number that Domoticz has and to change the IDX into the IDX you saw in Domoticz for this switch.
To send data from MicroPython to Domoticz we will need the urequests library which is supplied with the MicroPython distribution. So here is the full program:
import gc import machine import network import urequests as requests import time ssid = "YOUR-ROUTERS-NAME" pw = "PASSWORD" # wifi connection wifi = network.WLAN(network.STA_IF) wifi.active(True) wifi.connect(ssid, pw) print('Waiting for connection.',end="") while wifi.isconnected() == False: time.sleep(1) print('', end='.') print("") ip = wifi.ifconfig()[0] print("Connected with IP adress : "+ip) button = machine.Pin(14, machine.Pin.IN) while True: if button.value() == 0: print("Button pressed") requests.get("http://192.168.178.68:8080/json.htm?type=command¶m=switchlight&idx=23637&switchcmd=Toggle") gc.collect()
And that is all.
Don't forget to replace "YOUR-ROUTERS-NAME" and "PASSWORD" with your routers credentials.
The program is really simple.
First the libraries are loaded. We need the time, machine, network, urequests and gc libraries. All supplied when you installed MicroPython.
The program defines a button and then makes contact with your router. When the contact is established the Pico's IP address is printed in Thonny's shell.
The real magic happens in the while True: loop.
The program constantly checks if the button is pressed. When that happens the request is send. A confirmation that the button was pressed is printed in Thonny's shell. The program then sends the request and finally performs a garbage collection.
Do not omit the garbage collection. It frees up memory and using requests quickly clogs up your Pico's memory. So the garbage collection is really needed.
This is what will be shown in Thonny's shell.
Step 3: alter the switch appearance
Suppose you are going to use this as an alarm for a door or window. You would put a magnet on the window and a reed contact on the window frame. The reed contact acts as a switch.
In Domoticz press the "edit" button in your switch settings. 
Alter the Switch Type in Door Contact and the icon will change.
Pressing the button on your Pico now simulates opening and closing the reed contact and this will result in changing the switches appearance on your Domoticz screen.
Step 4: Using Events
Having a switch or contact changing on your screen is fun but not really practical.
In Domoticz's setup menu you can look at More Options and then Events.
Using the events you can write a script to test the switch and act on it's condition by setting an alarm on, sending a notification to your phone etc. etc.
Next time we are going the other way round.
The next story tells how to attach a led to your Pico (or other controller) and use a switch on Domoticz screen to set that led on or off.
Step 5: Use this to control your existing lamps
There is yet another purpose for this.
I have several outlet sockets that are controlled through 433Mhz. A famous brand here in the Netherlands is KlikAanKlikUit (KAKU). But you can also find them unbranded and cheap at thrift stores en DIY stores. Just play safe and make sure they comply to the local electricity rules.
One of these lights is in my mancave and called Mancave lamp 
Press on the Edit button of that lamp and you get the settings menu. We are not going to change anything. But we need thye first information that is displayed:
Idx : 3
That is the ID of this lamp in Domoticz.
And we can use that to set this lamp on or off from our Pico with MicroPython. We use the same program and only have to alter the request line:
requests.get("http://192.168.178.68:8080/json.htm?type=command¶m=switchlight&idx=3&switchcmd=Toggle"

And there you go. I can control this lamp now from the 433Mhz remote control, from the Pico and from Domoticz.
The fun part is that the MicroPython program uses "Toggle" to control the lamp. This means that if Domoticz sets the lamp on the Pico sets it off and the other way round.
Expansions.
Nobody holds you from sending multiple requests from MicroPython. So you can control several lamps and switches with one button attached to the Pico.
You can, of course, also attach multiple pushbuttons buttons to your Pico and use it as a remote control for controlling several lamps individually.
And you could have multiple Pico's with pushbuttons controlling the same lamp or outlet socket or whatever.
Just the Pico ?
Hell no. MicroPython works equally well on the ESP8266 and on the ESP32. You just have to adjust the pin numbers where the pushbuttons are attached to.
Arduino language (C++) ????
Yes you can do the same with the Arduino language. The code is although a lot more complicated. I did a story on how to do this in Arduino some time ago. You can find it here:
http://lucstechblog.blogspot.com/2020/01/sending-data-from-esp-to-domoticz.html
MicroPython ???
Micropython is a great language and easy to learn. A lot easier to learn as C++ (Arduino language). If you have no experience with MicroPython and want to learn, I can recommend my books on MicroPython with the Raspberry Pi Pico or Pico W for which you can find a link below this story.
Also check out my website that has lots of tips for programming in MicroPython:
https://micropython-tips.weebly.com/
Till next time
Have fun.
Luc Volders


