I have a Raspberry Pi running homegrown software to control an RGB LED strip. Currently it has a REST API to control the strip. It is connected to the same network as homeassistant but does not have any other sort of connectivity (no zwave, zigbee, bluetooth, etc). I’m looking to integrate this device into homeassistant so I can build more robust automations around it. In homeassistant land I imagine it would have the following entities:
Brightness: 0-100 (editable)
Pattern: Fixed set of enumerations (editable)
Online: binary indicating whether the device is available or not (not editable)
I’ve struggled to find documentation on this topic. I’d prefer to stick with a rest API or possibly something UDP based, but the source code is mine so I can modify it as needed.
You would need two things, a REST entity and your device template entity. The template entity handles all the normal HA commands like turn on/off, brightness, etc, and your definition of the template tells it what to do when those are requested and, in your case, send a rest call.
led_strip:
friendly_name: "LED Strip"
unique_id: my_led_strip
turn_on:
service: rest_command.led_turn_on
turn_off:
... your off command
It can obviously get more detailed from here, like getting the current state and attribute values via rest or even call a pyscript that handles the entire integration (my preferred method).
Create a helper of type number (named pi_lights_brightness in this case)
Create an automation that fires off when the helper changes:
alias: Pi Lights Brightness Set
description: Update Pi Lights Brightness
trigger:
- platform: state
entity_id: input_number.pi_lights_brightness
condition: []
action:
- service: rest_command.pilights_brightness
data: {}
mode: single
Some notes:
I found that mDNS domains don’t work in the rest_command, hence the raw IP in the yaml. I didn’t bother digging deeper since it’s easy to just give the Pi a static lease
This implementation assumes that the Rest endpoint is always changed via Home Assistant. If it is changed via another mechanism, then home assistant can get out of sync with what is actually happening at the endpoint. This could be solved via a rest sensor and more templating & automation, but I didn’t bother since I plan to only control it via Home Assistant
Same approach can be used for other functions, such as using a Dropdown Helper and another rest command to set the pattern
UPDATE: Got it working! I’m assuming the “rest_command.yaml” filename is important, I was using an arbitrary filename and it wasn’t working as expected.