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.

I realise this is an old thread but wondered how either of you ( @Jonaz80 or @spellinn ) had got on with integration between Cortex & HomeAsssitant.?

I’ve so far got automations pushing Zigbee-based temperature & presence data into Cortex, and HVAC status from Cortex back to HA. Also got HA able to trigger heating over-rides. I got some of this working using REST Commands, RESTful API and HA YAML files, but was finding debugging it just too painful.

I’ve now installed the Node-RED add-on any made much easier progress using that to both send & receive APIs between HA and Cortex.

I discovered a few Cortex quirks along the way.

Resurrecting another really old thread again but am revisiting my HA to Idratek and wondered if you’ve made much progress with NodeRed @jpdw

HI both - I posted about my progress here HAAPI Cortex - integration with Idratek's automation controller which contains detailed write up of everything so far.
Keen to add what you’ve done with Zigbee @jpdw please create a PR on the repo, or just DM me

Apologies for such a slow reply… I think the 3 of us have also posted on the same thread ‘elsewhere’.

To answer @spellinn 's question about NodeRed, the short answer is yes.

Longer answer is that I’ve managed to do Cortex->HA and HA->Cortex in both Yaml-in-HA and Node-Red.

For Cortex–>HA I found the Yaml method intensely frustrating to debug and get working and duplicating for a 2nd or 3rd Cortex device equally so. By contrast, with Node-Red I managed to get the Cortex->HA working a lot quicker. For me, the difference was that I could inspect/debug every point in the Node-Red flow, more so that (my capability) in HA.

However, I don’t “like” that I’m relying on a semi-external Node Red add-on to do something that HA can do on its own, but I’ve come to hate templating-yml-with-Jinja.

Whether using Node-Red or HA Yaml, there’s the need to map a Cortex object name and object id to an HA equivalent, and how/where to do that. In my Node-Red flows I’ve used a ‘switch’ node but that’s ‘hard coding’. Someone ( I think @Jonaz80) mentioned making a call to Cortex to get data [ for this mapping ] which I’d like to pursue at some point – getting rid of static mapping.

@Jonaz80 - I’m happy to share what I’ve achieved on the Node-Red side. Also what I’ve done in HA Yaml etc though I think your use of Yaml surpasses mine.

Suddenly thought it might be worth adding what are my motivation/intension with integrating HA & Cortex (apart from creating stuff to do :slight_smile: ) .

My intention is to get Cortex running my zoned-by-floor radiator heating. But this has had limited temperature and presence inputs - generally 1 sensor of each per floor. With HA & cheap battery zigbee I’ve now got coverage per-room so want to supply all this to cortex. In return I want to get cortex data onto the HA dashboards and drive zigbee radiator valves at sub-zone (room) level. Short-duration heating boosts can also be driven via HA dashboards / zigbee buttons etc,.

Hence why I’m trying to send sensor data in both directions.

Hi
I’ve continued trying to integrate Cortex HVACs into my HA, with some success.

My goal is to have day-to-day HVAC functions in an HA dashboard so that I don’t RDP into Cortex to:

  • check which HVAC zone has just caused the boiler to spark up
  • disable the HVAC temporarily – e.g. if I don’t want it the kitchen zone on if I know I’ve got the back door wide open for an extended time
  • see a zones current set point, whether it’s following occupied/unoccupied, delta between measured and set-point or measured and outside etc,.
  • how long a zone has been on & when it’s (currently) due to go off

I’ve been using the Node-RED integration between Cortex and HA as I find that a quick way to “prototype” the interaction - easy to debug & update. I realise that’s going in the “wrong direction” for an eventual HA integration but I’m seeing it a prototype of what would need to be translated to an integration in python “later”.

My progress so far gives me a dashboard table as below:

Currently separate buttons allow me to toggle each zone’s Mode between ‘heating’ and ‘off’ (I don’t have any cooling) and option to trigger it on for the run-on period (as set in cortex). I’m intending to merge these into the grid so it’d be press the appropriate bit of change/trigger it. Also a the entity icon etc,.

Behind the dashboard presentation it’s all based on an ‘HVAC’ binary sensor with the entity state being whether the HVAC is on (heating) or off. I’ve relied mostly on everything being event-driven out of Cortex:

  • Cortex HVAC object are configured as normal
  • The HVAC Stage Change is connected to a WebClient item
  • The WebClient item builds a POST to HA/Node-RED with all the useful info as json payload
  • Node-RED:
    • receives it
    • unpacks the json
    • does some conversions (e.g. the value ‘100’ if HVAC is ‘on’ to logic true etc),
    • calculates the Current, Above Setpoint and Outside Deltas
    • adds a ‘Friendly Name’
    • packs all except the State/Value as attributes of the Entity
    • maps everything to the right HA entity (based on a per-HVAC string in the json)

Example WebClient item:


[ only the zone name and HVAC object name in the payload are different for each HVAC ]

This is all Cortex → HA. What about HA → Cortex?

In the return path (e.g. to change the Mode or request heating for a run-on period) I’m using templated YML to send a request to Cortex, templating the Cortex Object ID, Port and Value.

To be consistent I should re-implement this in Node-RED, but its working as-is and in any case, these would need to be pythoned in any proper integration.

As these HA → Cortex seemed to ALWAYS return a “200 OK” confirming the request but regardless of the outcome, and with no payload, if I need feedback e.g. to confirm the new state or mode of the HVAC object, I found it’s possible to prod the WebClient Object, with a Port number specific to the WebClient Item and I’d then get (an updated) state info (which goes through the Node-RED stuff above, updating the HA entity…

Just like @Jonaz80 noted somewhere, the WebClient items don’t seem to be able to identify the triggering Object, and the json I’m using references the individual Object’s connections, so these are tediously created one-per-HVAC. In Node-RED the binary_sensor node is similar in that which most of the config is agnostic to the specific binary_sensor, the basic config of the node has a hard-defined entity name that cannot be taken from the incoming msg variable. So these are similarly near-identical duplicates (Grrrrrr) with a switch node diverting the incoming call from Cortex based on the ‘per-HVAC string in the json’.


(if only this could be replaced by a single binary_sensor object, based on an element in the msg)

There’s places where I’m mapping between Cortex and HA identifiers. Currently they are all text-based, including the string in the json which is only used in the WebClient Item and the switch in the Node-RED above - ie it’s neither a Cortex or HA string. In the HA->Cortex YAML I’ve referencing the HVAC object to act upon based on the Cortex ObjectID. I’ve realised that I should probably replace the ‘string in the json’ with the Object ID and then include that as another attribute in the HA Entity … then if you trigger an action (mode / run-on), in the HA automation rather than ANOTHER mapping (from HA Entity to Cortex Object ID), it would just retrieve the Cortex Object ID from the triggering HA Entity attribute… (if my description makes any sense!)

Anyway… My next target is to get room occupancy states into HA. I’ve got Cortex sending movement info, and HA pushing additional PIR data into Cortex, but not yet got Cortex’s Occupancy (instant or delayed, with timeouts etc) back to HA.

1 Like

This is great work on HVAC @jpdw - thank you for sharing and apologies it has taken me so long to respond.

For tracking room occupancy check out this in the foundations doc HAAPICortex/foundations.md at 65352130df5c5beafdc76f7da77c56daa6cf6b38 · JonaZ80/HAAPICortex · GitHub
A big challenge is that HASS doesn’t treat rooms as objects, so you end up using a ‘helper’ (input_boolean) to track the state, but it is not properly connected to the ‘Area’.

If you find a better way, please do share. I am setting up a dev instance to start playing more with this without jeopardising my production instance.