Integrating light via 3rd party device controller

Hi there! I am trying to integrate HA with another automation controller which has run my house quite happily for 15 years, but doesn’t have the UI that lovelace offers or secure remote access of cloudflared … so time to integrate :slight_smile:

So far I have HAOS setup with cloudflared & integrated an generic camera. HAOS polls a temperature sensor happily using REST Sensor. I have the curl commands figured out for controlling lights, and I can send push notifications on state change for objects in the 3rd party controller but am overwhelmed with how (best) to get it all working in HomeAssistant, so would really appreciate some guidance.

First off I want to end up with a light entity that will track the state of a light via the push notifications ( and occasional poll to ensure alignment after restart etc) and a switch that can control the light.
Also on the list would be to have an automation to capture a still or short vid from the camera when the door bell is pressed and push that to the companion apps.

The REST commands to control lights have all the parameters in the URL of the POST request, none in the payload so I don’t think the REST switch is right for me as I have separate end points for on and off commands. So looked at the the Command line switch just complains about the the curl referencing various lines in the command_line/*.py scripts
I cannot figure out how to add a light entity without an integration to eg Hue lights, there is no add entitiy on the /config/devices/dashboard, and I think I need an entity to add a webhook trigger to receive push updates. The only automation I want is to change the entity state.

I can see HA has options for scripts, templates etc etc but where to start and not overcomplicate???!!!

Any guidance much appreciated.
TIA
Jon

Are we to assume that you want to continue to use your existing PLC controller and just interface to the existing automations that you have created in said controller?
If so what PLC are you currently using?

Thanks for replying. Yes I want to keep the controller it is Idratek Cortex, Idratek also made all the PLCs and sensor modules. Tiny UK company, amazing kit, just needs a bit of UI magic really and ability to exchange messages.
I can share details of the curl that works from the command line if it would help.
Thanks J

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 :slight_smile:

Got my REST Command YAML sorted and the approach of using a light template works.
Discovered I have an authentication issue so that’s the next puzzle, have switched it off on the cortex controller for now and I can controll the light from HASS :smiley:

rest_command:
  familyrm_light_star_on:
    url: "http://192.168.0.78/api/v1/json/objects/family%20room%20star%203?Turn%20on=1"
    method: POST
    content_type:  'application/json'
    payload: '{}'

image

Hi @Jonaz80 I’ve just started integrating my Idratek implementation with HA so would love to know more about your setup.