Control GPIO Voltage

Hi and welcome to the openHAB community!
There is a binding for the GPIO interface, but AFAIK it will not help you very much.
You can also try the exec binding with some python scripts to do what you require!
Check here, and here!

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/fade.py”]

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.

Edit:

Also see

http://www.toptechboy.com/raspberry-pi/raspberry-pi-lesson-27-analog-voltages-using-gpio-pwm-in-python/

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.

2 Likes

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.

YMMV.

1 Like

You will always be a peach!

:wink:
1 Like

Many many thanks to everyone! :slight_smile:

1 Like

Sitemaps:

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

}

Items:

Switch LED “LED” { gpio=“pin:21” }
Dimmer Dimmer1 “Dimmer [%.1f]”
Rules:
rule “DimmerON”
when
Item LED changed
then
if(LED.state==ON)
executeCommandLine(“screen -dmS dimmer python /home/openhabian/asd.py”)
end

rule "DimmerOFF"
when
        Item LED changed
then
        if(LED.state==OFF)
                 executeCommandLine("killall python")
end

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

Python Script:

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(40,GPIO.OUT)
pwm=GPIO.PWM(40,100)
pwm.start(100)

while True:
        asd=input()
        pwm.ChangeDutyCycle(asd)

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.

2 Likes

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.

2 Likes