Switch.yaml

Hi all, I have a problem with my switch.yaml file. This works

platform: command_line
switches:
dimmer_v_rum:
command_on: “/usr/bin/curl -X GET http://192.168.1.136/cm?cmnd=dimmer%20100
command_off: “/usr/bin/curl -X GET http://192.168.1.136/cm?cmnd=Backlog%20dimmer%2010%3BPower%20OFF

But when I try to add a rest switch it does not work .
I m trying with

switch:

  • platform: rest
    resource: http://127.0.0.1:8126/container/grafana
    name: Grafana
    body_on: ‘{“state”: “start”}’
    body_off: ‘{“state”: “stop”}’
    is_on_template: ‘{{ value_json is not none and value_json.state == “running” }}’

Please could sameone point me what i m doing wrong?
Thanks

2 things before we can help you:

  1. format your code as it’s crucial
  2. post real information instead of “it doesn’t work”

Here

2 Likes

Do as @AhmadK said and the problem is probably the switch: in the beginning. You don’t need this when all your switches are configured in a separate file. Do you have something like

switch: !include switches.yaml

In configuration.yaml?

Something like that should probably work:

---
switch:
  - platform: command_line
    switches:
      dimmer_v_rum:
        command_on: "/usr/bin/curl -X GET http://192.168.1.136/cm?cmnd=dimmer%20100"
        command_off: "/usr/bin/curl -X GET http://192.168.1.136/cm?cmnd=Backlog%20dimmer%2010%3BPower%20OFF"

  - platform: rest
    resource: http://127.0.0.1:8126/container/grafana
    name: Grafana
    body_on: '{"state": "start"}'
    body_off: '{"state": "stop"}'
    is_on_template: '{{ value_json is not none and value_json.state == "running" }}'

I did not test it, nor do I have command line or rest switches…

1 Like

@Burningstone Yes I have “switch: !include switches.yaml” and it works.
The problem is when I add “platform:rest”
I can validate the yaml file in configurator is ok
but in the server I get this error
Invalid config for [switch.command_line]: expected a dictionary for dictionary value @ data[‘switches’][‘body_off’]. Got ‘{“state”: “stop”}’
expected a dictionary for dictionary value @ data[‘switches’][‘body_on’]. Got ‘{“state”: “start”}’
expected a dictionary for dictionary value @ data[‘switches’][‘name’]. Got ‘Grafana’
expected a dictionary for dictionary value @ data[‘switches’][‘platform’]. Got ‘rest’
expected a dictionary for dictionary value @ data[‘switches’][‘resource’]. Got ‘http://127.0.0.1:8126/container/grafana’. (See ?, line ?).

Read the link from @AhmadK link and format your code! Like this we are not able to help yoi.

1 Like

THANKS
Worked

You’re welcome, I had a hard time formatting and yaml-linting this example :wink:

1 Like