so, I’m using a raspberry pi 4 to control a small computer fan with PWM and I wanted to use home assistant to control the fan (I’m using a python script to control the PWM enabled fan I’ll give the code at the end) so I tried using home assistant OS, but I had a lot of problems so I am using raspberry pi OS and so I installed home assistant in a docker container and everything is installed correctly and I can load into home assistant on the browser so I set up my configuration.yaml with a command_line switch to control the fan and I’m using pigpio to control the gpio pins I have pigpio and the python script both in the same file as the docker container so there would be no problem’s there so when I run the docker command to control the script it works just fine the fan can be controlled so I added it to my configuration.yaml and went to go test it and I see the switch entity in devices and services when I click it, it doesn’t work so I checked the logs and it said this (
Logger: homeassistant.components.command_line
Source: components/command_line/switch.py:119
integration: Command Line (documentation, issues)
First occurred: 3:02:45 AM (9 occurrences)
Last logged: 3:06:41 AM
Command failed: docker exec homeassistant python3 /config/fan_control.py --speed 100
Command failed: docker exec homeassistant python3 /config/fan_control.py --speed 0
Command failed: /usr/bin/docker exec homeassistant python3 /config/fan_control.py --speed 100
Command failed: /usr/bin/docker exec homeassistant python3 /config/fan_control.py --speed 0
so, I’m confused and need help to figure out why it won’t work because that command works in the terminal heres the python script
import pigpio
import argparse
# Define GPIO Pin and Frequency
PWM_PIN = 18 # GPIO pin to control the fan
FREQ = 25000 # Frequency in Hz (25kHz)
# Initialize pigpio
pi = pigpio.pi()
if not pi.connected:
print("Failed to connect to pigpio daemon.")
exit(1)
# Argument Parser for Fan Speed
parser = argparse.ArgumentParser(description="Fan Speed Control")
parser.add_argument('--speed', type=int, help="Fan speed (0-100)", required=True)
args = parser.parse_args()
# Validate and Set Fan Speed
if 0 <= args.speed <= 100:
duty_cycle = int((args.speed / 100) * 255) # Convert 0-100% to 0-255
pi.set_PWM_frequency(PWM_PIN, FREQ) # Set frequency
pi.set_PWM_dutycycle(PWM_PIN, duty_cycle) # Set duty cycle
print(f"Fan speed set to {args.speed}%")
else:
print("Error: Speed must be between 0 and 100.")
# Clean up (Optional)
pi.stop()
and here is the configuration.yaml
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Command line switch configuration
command_line:
- switch:
name: "Fan Control"
command_on: "/usr/bin/docker exec homeassistant python3 /config/fan_control.py --speed 100"
command_off: "/usr/bin/docker exec homeassistant python3 /config/fan_control.py --speed 0"
please help I figure this out