Turn on/off WiFi on Pi4 with toggle in HA

I’m trying to turn Wifi (& bluetooth) on and off in Home Assistant with a toggle / switch.
Does it work?

maybe like so: (doesn’t work)


  - platform: command_line
      command_on: 'nmcli radio wifi on'
      command_off: 'nmcli radio wifi off'


1 Like

No (if you run Home Assistant Core in a Python vEnv - maybe).

I use the HA-Image installation.

But something like that works fine:

  - platform: command_line
    name: CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}'

So, Home Assistant OS …

Different thing. CPU Temperature queries a file on “disc”, using a de-facto standard program (cat). But nmcli is not present in the HA “image”.

And no -


OK…You mean it is better to use a container?
I tried at first the Container-Installation; it worked fine. But I couldn’t get any connections between e.g. HA and NodeRed …

That’s containers …

some months ago I installed docker (container) and inside the docker Home Assistant (but without Supervisor)…
And now I use HA-Image:

What is the best version to stay flexible. I want to be able to access to all features on my Raspberry Pi 4 either over commandline or via GUI.
Thanks a lot!

Tja …

Those are your official choices. Rasperry Pi OS, although based on Debian is not among the list of supported OS for Home Assistant Supervised, so it’s not supported on Raspberry Pi.

You could use Home Assistant Container with Portainer or Docker Compose to orchestrate, but you will loose the Add-On-Store.

Klingt alles nicht so vielversprechend :-/

Geht. Docker containers are like virtual machines, but for processes. Command line is executed at container level, not at host level. Even if you could manage to bring nmcli into the container, you would still lacking access to the host’s WiFi hardware. And that’s for a reason, for example /sys/class/thermal/thermal_zone0 exists on my RPi4, but not on my amd64 host.

If you want to communicate with the host, you need network services or file-system bases “semaphores”. That is:

  • You bind a host directory to a location into the container
  • You create something in HA, that puts a “marker” into that container directory (touch /my/special/dir/myfile)
  • You make something (like Cron) on the host monitor that directory and react on changes.
1 Like