Control GPIO Voltage

Ah, nice idea! Thanks :slight_smile:

Sorry for the double post.

Can i configure

  • If the switch is getting turned on run command x
  • It the switch is getting turned off run command y

If you read the documentation, that is pretty much the idea! I have linked the exec1 binding documentation! Please read the documentation on the openHAB documentation’s page according to your setup!

Sorry, but i don’t get it how to configure that.

My Item:
Switch Kette “Kette” { channel="exec:command:apc:run }
My Thing:
Thing exec:command:apc [command=“pyhton ~/Desktop/”]

When i trigger the Switch Kette, nothing is happening. Why?

Your problem is almost certainly because OH runs as the openhab user, not your login user.


Also see

1 Like

If I recall correctly, at least on a Pi (you didn’t mention but that’s what I assume you’re using), you can only set GPIOs to either 1 or 0 (i.e. 3.3V or 0V). I suggest you get a WiFi or zwave RGB controller instead.

True but there are ways to simulate voltages between 0V and 3.3V using PWM. Of course the LEDs he is using will have to support dimming for it to work.


You don’t want to simulate PWM in software. I doubt a Pi is fast enough. Just for example, a Fibaro RGBW needs to operate at a rate of 244Hz to get it flicker-free.

Dear Markus,
244 Hz for a transistor is like I am walking 1 km/h, slow pace I mean! The transistors generally speaking are not bound to a brand/technology! I have reached with Raspberry Pi far bigger frequencies!

For a transistor, yes. But for the massive software stack involved we’re talking about here ?
But feel free and try and let me know the outcome.

Oh, come on! Of course you can not do PWM control for LED from a rule in openHAB! Let’s set things straight assuming we are reasonable men (people, whatever gender)!
Of course a triac dimmer from the conception is fast, of course we can not emphasize on OH being an all-do machine, because the OS (Java) is not real time!
But, from my above points said to a guidance towards a technology/protocol, I think it’s way too far stretched!
So, instead of saying Fibaro, just say Z-wave! :wink:

See the link I supplied above. I’ve no experience, just some google foo that tells me it is possible at least with Python controlling a single LED.

No one is suggesting implementing PWM in OH.


1 Like

You will always be a peach!

1 Like

Many many thanks to everyone! :slight_smile:

1 Like


sitemap home label="Main Menu"
        Slider item=Dimmer1
        Switch item=LED



Switch LED “LED” { gpio=“pin:21” }
Dimmer Dimmer1 "Dimmer [%.1f]"
rule "DimmerON"
Item LED changed
executeCommandLine(“screen -dmS dimmer python /home/openhabian/”)

rule "DimmerOFF"
        Item LED changed
                 executeCommandLine("killall python")

rule "Dimmer2"
    Item Dimmer1 received command
    if (receivedCommand instanceof PercentType)
        executeCommandLine("screen -S dimmer -X stuff  " + (receivedCommand as PercentType)+ "\\n")

Python Script:

import RPi.GPIO as GPIO


while True:

It’s just a thought about using screen, there might be hundreds better solutions. Though its not meant for changing colors on ur LED strip, but u can control voltage by using PWM with the slider going from 0-100% power on openhab.


Hi George, now to turn this into a running gag, what about this ?
with best wishes !

1 Like

I don’t know the performance of this, but as I remember, you need a frequency of at least 600 Hz, 1 kHz for best performance.
Maybe @fwolter can provide a better inside view, but as per the example I think it deals with slow processes.

From the documentation of the PWM automation module:

This module is unsuitable for controlling LED lights as the high PWM frequency can’t be met.

Perhaps this binding can help. It supports the use of hardware generated pwm signals based on the internal 19.2 MHz crystal oscillator (54 MHz for Pi4B) which should be more than enough to control things like LEDs

I use it to drive a PWM fan at 25kHz, together with a CMOS to convert from 3.3V to 5V logic.


executeCommandLine("screen -S dimmer -X stuff " + (receivedCommand as PercentType)+ “\n”)

In the OH3 version the syntax for the executeCommandLine has changed, but I can’t get the parameter value to work properly.
I tried
executeCommandLine(Duration.ofSeconds(10), "screen", "-S", "dimmer", "-X", "stuff", "\""+(newValue.toString)+" \\n\"")
which killed the screen and
executeCommandLine(Duration.ofSeconds(10), "screen", "-S", "dimmer", "-X", "stuff", "\""+(newValue.toString),"\\n\"") which keeps the screen alive but does not impact the device (and running the command from the command-line does).

Any suggestions on how to send the ‘quoted stuff’ part of the command properly?