Build 24343 has fully HTTP actions, so cool things could be created (see docs). I've recently changed a couple of cams because better definition and I've found tha Reolink has a couple of cams that have spotlights. While the spotlights are driven by motion (so the cam could record in color), I wanted to drive them directly, so in case of any "security" event, like alarm on, door open, etc, I could use the lights to have a better video and make - you know - light.
So, if you want to use HTTP actions in VirtualController, just go to config
, entities
under your VirtualEntityController
section in reactor.yaml
, and add this:
- id: cams_retro_spotlights
name: "Retro Cam - Spotlights"
template: Binary Switch
# update the status at interval
http_request:
interval: 900 # 15m
url: "http://192.168.1.31/cgi-bin/api.cgi?user=foo&password=foo"
method: "POST"
force_json: true
headers:
"Content-Type": "application/json"
"Accept": "application/json"
body: '[{"cmd": "GetWhiteLed", "action": 0 , "param": { "channel": 0 }}]'
capabilities:
power_switch:
attributes:
state:
expr: "isnull( response ) ? null : response[0]?.value?.WhiteLed?.state == 1"
default: false
actions:
"on":
http_request:
url: "http://192.168.1.31/cgi-bin/api.cgi?user=foo&password=foo"
method: "POST"
force_json: true
headers:
"Content-Type": "application/json"
"Accept": "application/json"
body: '[{"cmd": "SetWhiteLed", "param": { "WhiteLed": {"bright" : 100, "channel": 0, "mode": 1, "state": 1}}}]'
target: state
expr: "isnull( response ) ? null: response[0]?.value?.rspCode == '200'"
"off":
http_request:
url: "http://192.168.1.31/cgi-bin/api.cgi?user=foo&password=foo"
method: "POST"
force_json: true
headers:
"Content-Type": "application/json"
"Accept": "application/json"
body: '[{"cmd": "SetWhiteLed", "param": { "WhiteLed": {"bright" : 100, "channel": 0, "mode": 1, "state": 0}}}]'
target: state
expr: "isnull( response ) ? null : response[0]?.value?.rspCode == '200' ? false : null"
Reolink has API where you have to post a JSON and the response will give you a JSON (in theory). It's not really JSON, so force_json: true
will do the trick for you. I'm lefting this as an example of cool things you could do with the new capabilites added/documented in 24343. HTH.