Toggle Rest command

Hello to everyone here, a very newbie here!!

I have home assistant up and running and controlling my garden lights using a nodemcu. I am turning these on/ off via rest_command and have them coming on and off at sunset and late evening using automations.

Now I would like to create a simple toggle so I can have a button on my dashboard.

I have created a helper input Boolean, to control this.

I found this link that appears to be perfect, I am trying to follow 123 Taras suggestion.

I have used the frontend to create the automation and this looks like

- id: '1627634515367'
  alias: Hanging Lights Toggle
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.hanginglights
  condition: []
  action:
  - service: rest_command.hanginglights{{trigger.to_state.state}}
    data: {}
  mode: single

In my logs I have the following error, I am unsure how to resolve this.

It says trigger undefined, however the trigger type is set to state?

thanks for all help and feedback.

If you use a RESTfull switch, you will get a toggle

1 Like

Hi thanks for the feedback, this wont work for me. The nodemcu code is written by myself and only supports http Get. It basically strips out the object I want to turn on/off from the passed in URL.

Fair enough, but that’s not REST, FWIW :wink:
Could you show the full error, please.

Yeah was pretty certain it didn’t meet standard, it does what I need for now.

The full error description, I can’t embed the image since a newbie.

Logger: homeassistant.automation.hanging_lights_toggle
Source: components/automation/_init.py:408
Error while executing automation automation.hanging_lights_toggle: Error rendering service name template: UndefinedError: ‘trigger’ is undefined

thanks

IDK.
Took your automation as you published it, just changed the input boolean, and I have the expected

Unable to find service rest_command.hanginglightson
Unable to find service rest_command.hanginglightsoff

Had another look at with it working for you.

Got it working I needed to create a card that handled the boolean input on/off.

I was turning the automation itself on or off.

Thank you

Indeed. It might seems obvious, but if an automation is not triggered, but only its actions ran manually through the GUI, there is no trigger object created.