I have been trying to create a simple switch that will call a aREST to switch on another switch on another harware device on the LAN but for the life of me, I cannot get it to show up in the front end - here is what I have in my configuration.yaml file:
Unfortunately it does not show up in the Dev/States page at all, rebooted and nothing - I have found that when I reboot, the aREST call is being made and then noting shows in HA GUI.
OK, found the solution with some serious help from the community - you know who you are and I am very grateful!
So, what I have been trying to do is to call a HTTP request when switch on a switch (REST or aREST), but meanwhile back at the ranch I have been requesting the STATUS of a switch with REST/aREST. Totally the wrong way round, so, to resolve this, here is what I have done and it works a treat:
Objective: Create a switch on the main UI to, when turned on, call a HTTP request and the switch the switch off. I use it in a scene, so, turn scene on, then toggle UI as off.
Reason: I have a Domoticz switch on another device (about 4 years old), that turn on a GPIO, turns on a motor to close a curtain for 7 seconds and then switch itself off. (yeah, yeah, I need to replace it with a new HASSIO Pi_Zero)
Logic: Works for me, not logic at all
Solution: Create a rest_command in configuration.yaml file, create an automation using a input_boolean
Code: (the formatting has gone a wee bit squiffy - somehow the editor and code blocks does not apply, check spacing)
[config\congiguration.yaml] Add the following:
rest_command:
my_request:
url: http://192.168.0.1:8080/json&whateverawsomecommandgoeshere
(congiguration.yaml includes this:)
input_boolean: !include_dir_merge_named input_boolean
automation: !include_dir_merge_list automations
[config\input_boolean\curtain.yaml] Add the following:
studycurtain:
name: Study Curtain
initial: off
[config\automations\curtain.yaml] Add th e following:
- id: AutomationNumber001
alias: ‘StudyCurtain’
trigger:
- platform: state
entity_id: input_boolean.studycurtain
to: ‘on’
from: ‘off’
action:
- service: rest_command.my_request
- service: input_boolean.turn_off
entity_id: input_boolean.studycurtain
This works for me - hope that this will help someone else trying to create a switch to call a HTTP request when switched on.