Home Assistant +433mhz

Hi!

After many hours trying to find a way to control my 433mhz power plugs I finally found this one. I’m now able to control my lights with the command sudo piHomeEasy 0 31418 -1 on but i can´t get it to work with Home Assistant…

I can see the switches but nothing happens when i pull the trigger

Do i have to do anything more?

I run HA on a Raspberry Pi 3 and i have this code in configuration.yaml

switch:
platform: command_line
switches:
lounge_leds:
command_on: “sudo piHomeEasy 0 31418 -1 on”
command_off: “sudo piHomeEasy 0 31418 -1 off”
command_state: “”
value_template: ‘{{ return_value == “1” }}’
friendly_name: Fireplace Lights
lounge_windows_leds:
command_on: “sudo piHomeEasy 0 31416 1 on”
command_off: “sudo piHomeEasy 0 31416 1 off”
command_state: “”
value_template: ‘{{ return_value == “1” }}’
friendly_name: Lounge Window Lights

Hi, did you try to use the automatic add option?

This is what I use to control my Etekcity plugs:

And here is the config I use:

switch:
#######################################################################
# RPi 433MHz Sender
#######################################################################
  - platform: rpi_rf
    gpio: 22
    switches:
      etekcity_0315_1:
#      downstairs_light
        pulselength: 183
        protocol: 1
        code_on: 291811
        code_off: 291820
        signal_repetitions: 15
      etekcity_0315_2:
#      printer
        pulselength: 182
        protocol: 1
        code_on: 291955
        code_off: 291964
        signal_repetitions: 15
      etekcity_0315_3:
#      monitor
        pulselength: 183
        protocol: 1
        code_on: 292275
        code_off: 292284
        signal_repetitions: 15

I would put the full path to piHomeEasy and check that the homeassistant user has permissions to run the piHomeEasy file.

By default the homeassistant user does not have sudo access. How are you running HA?

I have not heard about “automatic add option”. I tried to Google it but didn’t find anything

sensor:
  - platform: rflink
  - automatic_add: true

It will automatically add devices when you push a button on the device.

Okey so you mean I should replace my code with

Sensor:

  • platform: rflink
    • automatic_add: true

I would put the full path to piHomeEasy and check that the homeassistant user has permissions to run the piHomeEasy file.

Where should I put the full path?
Sorry for being a bit slow but this is my first HA device so I feel a bit lost…

Your HW is not an RF Link device, so that won’t work.

command_on: “sudo piHomeEasy 0 31418 -1 on”

Would become…

command_on: “sudo path/to/your/software/piHomeEasy 0 31418 -1 on”

so in your case if you followed the git hub instructions…

command_on: “sudo /usr/local/bin/piHomeEasy 0 31418 -1 on”

I tried this but still nothing happens when I press the switch button… Can it be a permission problem? and if so how do i give HA the right permission?

Have a look at chown --help, however I’m by no means a Linux expert :frowning: (You may need to preface the chown command with sudo)

You may also need to chmod the file to change the executeable permissions.

ls -n
…will show the permissions.

You are getting there. The user that is running HA does not normally have sudo rights, so will not be able to run this command. But you need to say how you are running HA before we can say that this is actually the problem.

i not sure if this is the information you need but…
Im running HA on a Raspberry Pi 3 with HASSbian Home Assistant built-in

That is it. You will be running HA as homeassistant user, and by default homeassistant user does not have sudo rights, so the command will not work.

To test this, try logging in as homeassistant user and try the command

$ sudo su -s /bin/bash -l homeassistant
homeassistant@raspberrypi:~ $ sudo piHomeEasy 0 31418 -1 on

and see if it works.

I think you naild it!

got this message:

So what to do now :smiley:

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

There are three approaches you can take.

You can add homeassistant to the sudo users list. However, this has security implications if you have (or intend to) allow access to HA over the internet. If you never intend to this, then it is straightforward - as user pi do

sudo adduser homeassistant sudo

If you do plan to access HA from outside your network, you really shouldn’t do that, as if there is a failure in HA, it gives hackers a greater chance of access to your machine.

There is a way to restrict sudo access to certain commands, that someone suggested in the forums a while ago. I can’t find it right now, but it is worth searching for, as a way to limit the exposure.

I think that the way to investigate first is whether you can run your command without root access. You shouldn’t need root access to access the gpio. Try looking around where you got the program, to see if they have solutions.

Looking through our forums, the following might give you access tot the gpio as homeassistant user

sudo usermod -a -G gpio homeassistant

which might work for your program. You can then run it just as

piHomeEasy 0 31418 -1 on

I did the “sudo adduser homeassistant sudo” command but i get this…

homeassistant@hassbian:~ $ piHomeEasy 0 31418 -1 on
setuid: Operation not permitted
piHomeEasy must be run as root.

It’s finally working!! :smiley:

Thank you so much everyone for your time and help!

what i did was to add edit sudoers and add:
homeassistant ALL=(ALL) NOPASSWD: ALL

after that everything was working

2 Likes