I’ve still got what must be one of the first ‘smart home’ lighting systems controlling around 20 lamps around my house. It’s a TCP brand product that they abandoned maybe a decade ago. It has a restful API which is quite well documented and I can turn on/off lights etc with a handful of shell commands i.e.
set_brightness: >-
curl -k --ciphers 'DEFAULT:!DH' 'https://192.168.1.2/gwr/gop.php?cmd=RoomSendCommand&data=<gip><version>1</version><token>5mcopjq4x2j5rv429pbbkp7tbvq0ubtpov4j5zs8</token><rid>{{ rid }}</rid><value>{{ brightness }}</value><type>level</type></gip>&fmt=xml'
as it has only got TLS1.2 I had to figure out how to get around using https (it doesn’t respond to plain http) but that’s not my issue.
What I’m struggling with is getting the current status so I can track changes to lights coming from other sources. I have a working ‘get_carousel’ shell command that returns a long xml list for this but I’m finding it difficult making a regular request and parsing it out to sensor states.
As a first attempt, I tried to get the whole response back like this:
get_carousel: >-
curl -k --ciphers 'DEFAULT:!DH' 'https://192.168.1.2/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>5mcopjq4x2j5rv429pbbkp7tbvq0ubtpov4j5zs8</token><fields>status</fields></gip></gdata></gwrcmd></gwrcmds>&fmt=xml'
sensor:
- platform: command_line
name: Carousel Data
unique_id: carousel_data_sensor
command: "curl -k --ciphers 'DEFAULT:!DH' 'https://192.168.1.2/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>5mcopjq4x2j5rv429pbbkp7tbvq0ubtpov4j5zs8</token><fields>status</fields></gip></gdata></gwrcmd></gwrcmds>&fmt=xml'"
value_template: "{{ value }}"
scan_interval: 300
No sensor of that name is to be found though. Obviously I’ve not understood things right. Studying various examples I found other approaches apparently including the use of rest like so:
rest:
- resource: "http://date.jsontest.com/"
scan_interval: 120
sensor:
- unique_id: rest_test1
name: test1
value_template: >
{{ value_json.date }}
But that doesn’t create a sensor either. Confusingly, when I look for HA documentation it seems I should be using the RESTful Command but I can’t figure out how to get my return data into a sensor(s) from which to update the current state of things. (I realise this is several steps on - for now I just want to see the XML payload in its entirety)
I may well be going about this in the wrong way. AppDaemon may be a better approach but I can’t seem to get round the TLS1.2 issue with that.