I’ve read lots, watched many vids and made some progress…but not quite there
Using a webhook API call I can create a binary sensor entity and set the status from a 3rd party call. I’ve also created a command line switch …although the curl command is right it isn’t working. Error message at bottom.
I’ve read about automations (this was interesting Create a custom enitity/sensor from a webhook JSON payload ) and then used this to create a template that called a rest_command … but there is a problem with the YAML that I cannot figure out.
Which of these (or another) is the best way to reflect status of and control a light that can ping a status to HASS on change?
TIA
template:
- trigger:
- platform: webhook
webhook_id: cortex-familyrm-light-star
binary_sensor:
- name: "Star Light"
state: "{{ trigger.json.light_familyrm_star }}"
device_class: light
switch:
- platform: command_line
switches:
familyrm_light_star:
friendly_name: Star Light
command_on: >
curl -X POST -H 'Authorization: Basic ' secret! CortexAuthBasic -d '{}' 'http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn on=1'
command_off: >
curl -X POST -H 'Authorization: Basic <snip>' -d '{}' 'http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn off=1'
light:
- platform: template
lights:
familyrm_light_star2:
friendly_name: "star2"
turn_on:
service: rest_command.familyrm_light_star_on
turn_off:
service: rest_command.familyrm_light_star_off
rest_command:
- familyrm_light_star_on:
url: "http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn on=1"
method: POST
headers:
authorization: Basic !secret CortexAuthBasic
content_type: 'application/json'
payload: '{}'
- familyrm_light_star_off:
url: http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn off=1
method: POST
headers:
authorization: Basic !secret CortexAuthBasic
content_type: 'application/json'
payload: '{}'
Error in above from config.yaml:
Invalid config for [rest_command]: expected dictionary for dictionary value @ data['rest_command']. Got [OrderedDict([('familyrm_light_star_on', OrderedDict([('url', 'http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn on=1'), ('method', 'POST'), ('headers', OrderedDict([('authorization', 'Basic !secret CortexAuthBasic')])), ('content_type', 'application/json'), ('payload', '{}')]))]), OrderedDict([('familyrm_light_star_off', None), ('url', 'http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn off=1'), ('method', 'POST'), ('headers', OrderedDict([('authorizati.... (See /config/configuration.yaml, line 84).
Errors when pressing the command line switch
Logger: homeassistant.components.command_line.switch
Source: components/command_line/switch.py:183
Integration: command_line (documentation, issues)
First occurred: 10:16:38 PM (1 occurrences)
Last logged: 10:16:38 PM
Command failed: curl -X POST -H 'Authorization: Basic <snip>' -d '{}' 'http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn off=1'
Logger: homeassistant.components.command_line
Source: components/command_line/__init__.py:26
Integration: command_line (documentation, issues)
First occurred: 10:16:38 PM (1 occurrences)
Last logged: 10:16:38 PM
Command failed (with return code 3): curl -X POST -H 'Authorization: Basic <snip>' -d '{}' 'http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn off=1'
Response to curl command when run from command line (added the -i switch to confirm response good):
$ curl -X POST -H 'Authorization: Basic <snip>' -d '{}' -i 'http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn on=1'
HTTP/1.1 200 OK
Connection: close
Content-Type: Content-Type: application/JSON
Content-Length: 65
{
"CortexAPI":{
"Code":"200",
"Message":"OK"
}
}
Thanks for reading this far