I need help to create a simple switch

Hello Community,

i need help to make a simple switch. I am not a developer so I ask for help too.
I converted an IKEA PS 2014 hanging lamp from manual to automatic operation.

A Pi Zero and a “simple” script that enables the lamp to be controlled via the REST API are used for control.

With curl 0.0.0.0:5000/open and with curl 0.0.0.0:5000/close, I can open and close the lamp from the openHAB.

And now the question comes: How do I build the switch? Sorry for the question, I can only assemble everything, but I have no idea about programming.

Thanks 4 help

Your should write a script that uses the Exec Binding. Just search the forum.

Another question is how do you automate the open/ close process and how about create some kind of dimming modus?

Exactly. Write two hash scripts: one contains curl 0.0.0.0:5000/open and the other one curl 0.0.0.0:5000/close. Give permissions to the user openhab so it can execute them with sudo chmod a+x script1.sh script2.sh and then integrate them into openhab with the exec binding. Make sure to not forget the exec.whitelist!

1 Like

The opening and closing is controlled by a stepper motor if that’s what you mean.
Gradually opening the lampshade would be the next step.
But now I need a simple switch that opens and closes the lamp.

The difficulty here is to build the switch in such a way that when I press the switch on the cell phone the lamp goes on and when I press it again the lamp goes back on.

Theoretically a very simple on / off switch, but I have absolutely no idea how to build this switch so that it works and not when I press the switch again and the switch opens again. Then the lamp is rubbish.

I don’t want to use two switches via the exec binding. That would only be an emergency solution. I just want one switch.

It would certainly be easier if we talked in German and not in my bad English. :wink:

Here you go:

exec.things

Thing exec:command:Command_Fussventilator_An [command="/etc/openhab2/scripts/Steckdosen/1_an.sh", interval=0]

Thing exec:command:Command_Fussventilator_Aus [command="/etc/openhab2/scripts/Steckdosen/1_aus.sh", interval=0]

*.items

Switch Steckdosen_Fussventilator “Fussventilator” (Gruppe_Steckdosen) [“Switchable”]

Switch Steckdosen_Fussventilator_An {channel=“exec:command:Command_Fussventilator_An:run”}

Switch Steckdosen_Fussventilator_Aus {channel=“exec:command:Command_Fussventilator_Aus:run”}

*.rules

rule “Steckdosen Power: Fussventilator”

when

Item Steckdosen_Fussventilator received command

then

if(receivedCommand == OFF){

    logInfo("Rule triggered", "\"Steckdosen.rules: Steckdosen Power: Fussventilator\": aus")

    Steckdosen_Fussventilator_Aus.sendCommand(ON)

    Steckdosen_Fussventilator_An.postUpdate(OFF)

}

if(receivedCommand == ON){

    logInfo("Rule triggered", "\"Steckdosen.rules: Steckdosen Power: Fussventilator\": an")

    Steckdosen_Fussventilator_An.sendCommand(ON)

    Steckdosen_Fussventilator_Aus.postUpdate(OFF)

}

end

*.sitemap

Switch item=Steckdosen_Fussventilator mappings=[OFF=“AUS”, ON=“AN”]

With the rule you get one switch that controls turning the lamp on and off. Just exchange the scripts

Any Questions?