Stateless switch component (separate on off buttons) possible?

Hi everyone,

I am building a RESTful bridge device for use with Home Assistant. It will be open source, although I haven’t uploaded my code to github yet. The project primarily uses Python and Flask and runs on a Raspberry Pi. I’m currently using the pi_switch library to relay 315 and 433 MHz RF signals.

Using curl, I am able to successfully send JSON POST requests to the bridge device to turn my appliances on and off. The RF outlets themselves are stateless. There are individual on and off buttons on the original remote control.

The current work-around is to configure two separate switches. One RESTful switch device to send an ON request and another to send an OFF request.

switch:
   platform: rest
   resource: http://192.168.1.110:80/rf
   name: "Floor Lamp ON"
   body_on: "{\"code\":\"13376\",\"bits\":\"15\",\"pulse\":\"800\",\"protocol\":\"2\"}"
   body_off: "{\"code\":\"13376\",\"bits\":\"15\",\"pulse\":\"800\",\"protocol\":\"2\"}

   platform: rest
   resource: http://192.168.1.110:80/rf
   name: "Floor Lamp OFF"
   body_on: "{\"code\":\"13344\",\"bits\":\"15\",\"pulse\":\"800\",\"protocol\":\"2\"}"
   body_off: "{\"code\":\"13344\",\"bits\":\"15\",\"pulse\":\"800\",\"protocol\":\"2\"}

Instead of using this work-around, I was hoping there was a configuration to somehow allow two individual on/off buttons. I recall seeing a roller shutter component in the demo a few months ago. It had individual up, down and stop buttons. Is it possible to customize/override a switch component to do this?

If this isn’t possible with the current build, I would be quite interested in adding this functionality somehow. Perhaps by adding support for a “stateless” configuration parameter for switches?

1 Like

I am not sure I understand your problem.
But maybe assumed_state is what you are looking for: https://home-assistant.io/getting-started/customizing-devices/

1 Like

That was exactly what I was looking for. Thank you Daniel!

The switches are now displaying individual on and off buttons.

Originally, I tried adding the customize: entry immediately after switch:, which did not work. The customize: tag had to be a child of the homeassistant: tag. For multiple switches, I also had to add to prefix each platform entry with a hyphen.

switch:
- platform: rest
  resource: http://192.168.1.110:80/rf
  name: "Floor Lamp"
  body_on: "{\"code\":\"13376\",\"bits\":\"15\",\"pulse\":\"800\",\"protocol\":\"2\"}"
  body_off: "{\"code\":\"13344\",\"bits\":\"15\",\"pulse\":\"800\",\"protocol\":\"2\"}"

- platform: rest
  resource: http://192.168.1.110:80/rf
  name: "Fan"
  body_on: "{\"code\":\"13328\",\"bits\":\"15\",\"pulse\":\"800\",\"protocol\":\"2\"}"
  body_off: "{\"code\":\"13320\",\"bits\":\"15\",\"pulse\":\"800\",\"protocol\":\"2\"}"

If you found the documentation unclear, it would be great if you could help improve it.
You find “Edit this page on GitHub” in upper right corner of the documentation pages.

1 Like