I am not using Home Assistant yet. This is my first device, and for now I am skiping HA.
I recently replaced one of my home lights with a Nanoleaf panels set.
I am trying to program, using ESPHome, a Sonoff T0EU2C to control nanoleaf panels.
Button 1 would be toggle on/off and button 2 next light scene.
I already managed to turn on and of the light through http_request.send.
Unfortunatly, nanoleaf API does not have a toggle function.
I would like to:
send a get request to get the current on off state
store the response in a global variable
send the PUT request toggling state
My current problem is: How do I parse the GET response ({value: on/off})?
Can I do it in the YAML file?
globals:
- id: leaf_state
type: int
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
id: button_1 on_press:
then:
- http_request.get:
url: http://192.168.1.74:16021/api/v1/myAuthorizationToken/state/on
... parse the result and place it on global leaf_state
- http_request.send:
method: PUT
url: http://192.168.1.74:16021/api/v1/myAuthorizationToken/state
headers:
Content-Type: application/json
json: |-
root.createNestedObject("on");
root["on"]["value"] = !leaf_state;
verify_ssl: false
Thanks for the inputs @KTibow and @nickrout. @KTibow, the problem with that is the switch getting out of sync if I use the phone or the buttons on the nanoleaf controler.
Thats why I want to question (GET) the device prior to toggling. To resync beforehand.
Yes it does. I even tried it once.
But having a server running (even in a pi) to control a single light and a wall switch is a bit overkill.
I will go with HA when I have some more devices to manage.
I managed to make it work.
I dismissed the visual track for on / off so that I had no synchronization problems. It also prevents needless relay activation.
How I dit it: