Hi All,
I’m really new to HA and looking for some assistance please.
I’m running HA v0.116.2 on a Pi 4 and at this stage, not doing anything overly complicated: looking to learn and expand.
I’ve got the basic build setup, the mobile app installed and configured on my phone, and a few Tuya switches setup and running successfully, but I think it’s fair to say I’m still not “Comfortable” with really and truly understanding or using the configuration.yaml file.
My next goal is for HA to control a 3rd party device I have that exposes REST API’s (GET / POST) to allow control, however I’m a little confused how to get HA firing these.
The API’s exposed have a POST Method on the device I’m controlling but don’t report their state in the POST responses (you just get a 200 response), and I don’t want to be polling these - just firing to prod the command. Likewise, they use a base64 encoded Basic Bearer token Authentication method in the header.
I read through the REST and RESTful integration docs and a few forum posts / Youtube vids, but I’m not sure these are right for me as I understand they’re reliant upon the same REST API reporting a on/off state (for a switch) in the response which it’ll poll frequently: I don’t want or need this. (Correct me if I’m wrong here)
As far as I can tell, I have an option of using a “command line switch” - but even reading the docs (here https://www.home-assistant.io/integrations/switch.command_line/) I’m sadly still a little lost.
My simple REST API would look like;
URI - http://{mydeviceIP}:{port}/api/v1/Objects/522?7=1
Header - Authorization : Basic Y2xnZmZgcMk6Q2wxZmZwcwRh
Which I can fire as an API request from Postman etc successfully - With postman telling me that the cURL (which I’m not familiar with using) for this being;
curl -L -X POST 'http://<deviceIP>:<port>/api/v1/Objects/522?7=1/api/v1/Objects/522?7=1' -H 'Authorization: Basic Y2xnZmZgcMk6Q2wxZmZwcwRh'
which also seems to tally with what I’ve googled about “Create curl API post request” too … however trying to fire this in a windows cmd or Powershell, doesn’t appear to work … (Confused here) - I just get;
Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Authorization: Basic
Y2xnZmZgcMk6Q2wxZmZwcwRh" value of type "System.String" to type "System.Collections.IDictionary".
At line:1 char:93
+ ... 1/Objects/522?7=1' -H 'Authorization: Basic Y2xnZmZgcMk6Q2wxZmZwcwRh'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I’ve attempted to add this into my configuration.yaml file as;
switch:
- platform: command_line
switches:
kitchen_light:
command_on: "curl -L -X POST 'http://<deviceIP>:<port>/api/v1/Objects/522?7=1' -H 'Authorization: Basic Y2xnZmZgcMk6Q2wxZmZwcwRh'"
command_off: "curl -L -X POST '<deviceIP>:<port>/api/v1/Objects/522?7=2' -H 'Authorization: Basic Y2xnZmZgcMk6Q2wxZmZwcwRh'"
… and restarted HA … which then shows me the switch.kitchen_light entity and in services, I can hit “Call Service” with the “switch.turn_on” service and “switch.kitchen_light” entity, but nothing happens …
I’m now not sure whether I’m just not getting the curl right (which is highly possible given I’ve never used it before) or whether I’ve got something wrong in the yaml …
Further, I want this to appear in the Lovelace UI just like my TUYA switches do, with an on/off toggle switch (thus firing the API request each time it’s toggled) if possible … but adding it just appears to show it as a massive lightning bolt that when pressed, also does nothing …
Really sorry if this is me being a newbie and missing something which anyone with any experience will be tutting and rolling their eyes at, but I’m just starting out learning here so please forgive me
Really appreciate any help you can offer.