Pilight Integration

I’m trying to integrate my working Pilight installation into Homeassistant.
Pilight runs on an external Raspberry and I can switch sockets via SSL, HTTP and via Pilight’s web interface.
Here is my entry in the configuration.yaml

pilight:
  host: 192.168.1.149
  port: 5001
  send_delay: 0.4

switch:
  - platform: pilight
    switches:
      my_switch:
        on_code:
          protocol: pollin
          systemcode: 16
          unitcode: 16
          'on': 1
        off_code:
          protocol: pollin
          systemcode: 16
          unitcode: 16
          'off': 1
Unable to prepare setup for platform pilight.switch: Unable to set up component.
                             19:08:15 –                              (FEHLER)                              setup.py
Logger: homeassistant.setup
           Source: setup.py:339                       
           first occurred:                  19:08:15                  (1 occurrences)
           Unable to prepare setup for platform pilight.switch: Unable to set up component.

                                                                                                                                                    
Error during setup of component pilight
                             19:08:15 –                              (FEHLER)                              components/pilight/__init__.py
Logger: homeassistant.setup
           Source: components/pilight/__init__.py:78                       
           First occurred:                  19:08:15                  (1 occurrences)
           Last logged:            19:08:15

Error during setup of component pilight Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 235, in _async_setup_component
    result = await task
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/pilight/__init__.py", line 78, in setup
    pilight_client = pilight.Client(host=host, port=port)
  File "/usr/local/lib/python3.10/site-packages/pilight/pilight.py", line 93, in __init__
    answer_1 = json.loads(self.receive_socket.recv(1024).decode())
  File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I can’t find any devices or entities.
After a reboot the log says:

What ist wrong?

Hi
I have the same issue, did you ever resolve it?
Thanks

Hi,
Just starting with home-assistant; trying to add my pilight, but same issue here, followed by:

2023-10-08 22:45:44.186 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform pilight.switch: Unable to set up component.

I am using the latest docker version of home-assistant…
So im am curious for the solution… anyone an idea?

As i am afraid that there is no quick solution for this issue, and i want to move on; i took another road to get my things done. The pilight has also an API; which i used earlier in my openhab config.
So now i added the following config into configuration.yaml:

command_line:
  - switch:
      name: Lamp Linkerraam
      unique_id: wklinkerraam
      command_on: >
        curl "http://<pilight_ip>:5001/control?device=<PiLightName>&state=on"
      command_off: >
        curl "http://<pilight_ip>:5001/control?device=<PiLightName>&state=off"

This works perfectly for me, as i am not using the original remote’s. :slight_smile:
Hoping to help someone with my approach.

There may be an issue with the “config.json” file for pilight.

Here is my working config:

# configuration.yaml
pilight:
  host: 127.0.0.1
#  host: 192.168.1.106
  port: 5000
  send_delay: 0.5
# switch.yaml
- platform: pilight
  switches:
    Mylamp:
      on_code:
        protocol: kaku_switch_old
        unit: 0
        id: 0
        'on': 1
      off_code:
        protocol: kaku_switch_old
        unit: 0
        id: 0
        'off': 1

I had to make some changes to the config.json file
Location: /etc/pilight/config.json
The key changes I needed to make were: “port” , “standalone”, “gpio-platform” and the “hardware” sections. Just make sure you stop pilight before you make the changes or it will overwrite them with the default values.

{
        "devices": {},
        "rules": {},
        "gui": {},
        "settings": {
                "port": 5000,
                "log-level": 6,
                "pid-file": "/var/run/pilight.pid",
                "log-file": "/var/log/pilight.log",
                "standalone": 0,
                "webserver-enable": 1,
                "webserver-root": "/usr/local/share/pilight/webgui",
                "webserver-http-port": 5001,
                "webserver-https-port": 5002,
                "webserver-cache": 1,
                "whitelist": "",
                "gpio-platform": "raspberrypi3"
        },
        "hardware": {
                "433gpio": {
                        "sender": 0,
                        "receiver": -1
                }
        },
        "registry": {
                "webserver": {
                        "ssl": {
                                "certificate": {
                                        "location": "/etc/pilight/pilight.pem"
                                }
                        }
                },
                "pilight": {
                        "version": {
                                "current": "8.1.5"
                        }
                }
        }
}