Hi there, I’m trying to set PWM output for my LED but the output is very strange. I tried to change the duty cycle but the output is just on with 100% brightness(duty cycle=32%-100%) or just flash once(duty cycle=0%-31%).
Not sure if I have an answer, but a couple issues I see here.
Be sure that when you post YAML, you use preformatted text (not blockquote) so that we can spot formatting errors. Indentation is significant.
Not a fix, per se, but you can call that shell_command directly without a script.
service: shell_command.pwm1
Take a look at input_select.pwm_led in your states dev tool (icon in left-sidebar, looks like < >) - is the state 50% (including a % sign)?
You can’t use a script as a trigger. That probably threw an error (look in home_assistant.log in the same directory as your config).
What are you trying to use as a trigger? Ignoring the service as a trigger, you’ve got it set so that this automation will trigger only when you change the input_select.pwm_led to a state of 50%.
As a sanity check - what happens when you run “python /home/hass/pwm1.py” from an SSH session? Does it work on it’s own? If not, it won’t work when HASS calls it.
@ ih8gates
Thank you very much and sorry for the late reply.
Yes, the state of the input_select.pwm_led is 50% including a % sign. I’m trying to use input_select as a trigger to run the python script. I have done some modification to the python script and the configuration.yaml file and it is now able to make it run from an SSH session.
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(29, GPIO.OUT)
p = GPIO.PWM(29, 50)
while True:
p.start(10)
pwm100.py
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(29, GPIO.OUT)
p = GPIO.PWM(29, 50)
while True:
p.start(100)
but there’s still some problem. I have multiple similar python scripts that give different pwm output. After running some python scripts, the output gets weirder and the outputs of multiple pwm clashed making the led giving different brigtness at the same time. I think is because the previous processes are not terminated. Is there any way or alternatives that can terminate the unwanted python script or should I modify the python scripts (pwm10.py and pwm100.py) ?
That’ll pass brightness=100 to your shell_command.
I’m not a python guy, so I’m not sure how to handle arguments passed through the command line inside your py script.
BUT - this would give you a single script that you’d have to stop rather than several. You’d just need to work out the command to kill a running script.