Where is my switch?

I have a DALI light connected to a Lunatone DALI-2 IOT controller.
I can control the light using the RESTful Command integration:

rest_command:
    dali_light_1_off:
        url: "http://192.168.8.155/device/1/control"
        method: post
        headers:
            accept: "*/*"
            Content-Type: "application/json"
        payload: '{ "switchable": false }'

When I add the above code in the configuration.yaml, I have a service available called “RESTful Command: dali_light_1_off” which I can call to turn off the light.

I now want to create a RESTful switch that turns on/off the light.
I added the following code to the configuration.yaml:

switch:
  - platform: rest
    name: rest_dali01
    resource: http://192.168.8.155/device/1/control
    method: post
    body_on: '{ "switchable": true }'
    body_off: '{ "switchable": false }'
    headers:
        Content-Type: application/json

Now my question: Where do I find that switch?
I can’t seem to find an entity nor a service in relation to that code.
Am I missing something?

Thank you for any help.
Akio

Assume you restarted HA ?

jep…
multiple times

No errors in logs ?

did you look in dev tools - states ?

Hmm…
Thanks for the tip. I found the following error.

Logger: homeassistant.components.rest.switch
Source: components/rest/switch.py:112
Integration: RESTful (documentation, issues)
First occurred: 12:58:19 (1 occurrences)
Last logged: 12:58:19

Got non-ok response from resource: 405

Now what could be the issue here?

Maybe try command line switch as mentioned here ?

I would guess the problem is that the RESTful switch periodically makes a GET request to the specified resource URL to check the state of the switch. It would seem making a GET request to that same URL results in an error response.

Does the light have a different URL you can use (with a GET request) to retrieve its current state? If so, you should specify that in the state_resource option. And then you should also fill in the is_on_template option to extract the state of the switch from the response.

1 Like

THAT WAS IT:
I added
state_resource: http://192.168.8.155/device/1
to the definition and now the switch shows up as an entity.

Thank you.

Great! Is it also showing the correct state after you turn the switch on and off via the HA entity, and also when you turn it on and off manually (at the actual switch, assuming that’s possible)?

Yes it does. For that I added the line:
is_on_template: "{{ value_json.features.switchable.status }}"

it has a little delay bit it works

1 Like