Hello,
My first post here.
I ve been using home assistant and I ve been able to set some nice lovelace dashboards using various stuff : Daiking AC, Philips Hue and also setup a Deconz link for my other Zigbee peripherals, even integrated a webcam managed by motion on a raspberry pi so, pretty cool stuff so far, love the interface.
I recently ordered a Xiaomi Mi Smart Plug which I can activate from lovelace dashboard just fine. I m also able to get the power consumption.
Since everything is now in motion, I wanted to start playing with simple automation but so far, no luck.
My goal :
- Activate my Xiaomi power plug at 9PM everyday
- Deactivate my XIaomi power plug at 1AM every day
No condition, simple stuff (at least I thought that would be an easy thing to do) much like two daily crontabs.
I tried playing with automation.yaml : Unsuccessfull
I also tried to play with Rest API calls : Meh…
Let me start with the API Calls as we can easily query metadata of the device.
curl -s -X GET -H "Authorization: Bearer $Token" -H "Content-Type: application/json" http://localhost:8123/api/states/switch.smart_plug_3 | jq .
{
"entity_id": "switch.smart_plug_3",
"state": "on",
"attributes": {},
"last_changed": "2021-03-25T11:06:19.072706+00:00",
"last_updated": "2021-03-25T11:29:18.653351+00:00",
"context": {
"id": "c823a3d382ce70ceaf3a80d297c34462",
"parent_id": null,
"user_id": "1ef411b991514a569622d31f192a3b2a"
}
}
So far so good, my power plug is on and powering my devices alright.
Now if I try to change the state to off :
# Sending a payload with state = off
curl -s -X POST -H "Authorization: Bearer $Token" -H "Content-Type: application/json" -d '{"state": "off"}' http://localhost:8123/api/states/switch.smart_plug_3 | jq .
{
"entity_id": "switch.smart_plug_3",
"state": "off",
"attributes": {},
"last_changed": "2021-03-25T11:34:44.919181+00:00",
"last_updated": "2021-03-25T11:34:44.919181+00:00",
"context": {
"id": "00196f8b49bd8b9e3df7184dffaea4df",
"parent_id": null,
"user_id": "1ef411b991514a569622d31f192a3b2a"
}
}
# Checking if the change took effect
curl -s -X GET -H "Authorization: Bearer $Token" -H "Content-Type: application/json" http://localhost:8123/api/states/switch.smart_plug_3 | jq . {
"entity_id": "switch.smart_plug_3",
"state": "off",
"attributes": {},
"last_changed": "2021-03-25T11:34:44.919181+00:00",
"last_updated": "2021-03-25T11:34:44.919181+00:00",
"context": {
"id": "00196f8b49bd8b9e3df7184dffaea4df",
"parent_id": null,
"user_id": "1ef411b991514a569622d31f192a3b2a"
}
}
The state does indeed switch to off but the power plug is still providing power.
I expected the changed state to trigger and actualy turn off my power plug.
NOTE : I checked the syntax when I turn the power plug to off using lovelace dashboard and If I query the sate of the device, the syntax is indeed “off” and not “Off or OFF”
I browsed official documentation and various posts but so many ways to do things, none worked for me after trying over and over for a day. So I figured I’d come beg for help here
Also, if it could work using automation.yaml that would be great.
One of the things I tried… :
- id: Test Light Activation
alias: Lights On
trigger:
platform: time
at: '21:00:00'
action:
- service: switch.turn_on
entity_id: switch.smart_plug_3
data:
state: on
- id: Test Light Activation
alias: Lights Off
trigger:
platform: time
at: '01:00:00'
action:
- service: switch.turn_off
entity_id: switch.smart_plug_3
data:
state: on
Idealy I wanted a blue print to be able to configure this from the dashboard by providing a “Time to power on” and “Time to power off” but at this point, I would just be happy with a configuration file or an api call through crontab…
Thanks