If you overwrite a state via the states dev tool or the API, it will not impact the actual device. If the device state is being polled, it will overwrite the state in the state machine the next polling.
So, how can I exactly change the values of devices’ states (on/off) and attributes (e.g. brightness or rgb on a WiFi LED Bulb) when I get triggered through a Websocket client (like this one) remotely (by a Firebase change state function in the same websocket client in my case)?
Sorry if it’s a dumb question. I’ve spent days searching in forums and still no answer.
I read it but I can’t figure out how exactly implement it, I’ve tried:
// Function that gets triggered on a Firebase DB change
var actuatorChanges = database.ref('actuador/a2');
actuatorChanges.on('child_changed', function(data) {
// Tried to apply this, but the socket closes immediately
// I'm also sure data.val().brightness returns a number and not a string
ws.send('{"id": 24,"type": "call_service","domain": "light","service": "turn_on", //Opt "service_data": {"entity_id": "light.yeelight_rgb_id", "brightness": '+data.val().brightness+'}}\n');
});
Calling the REST API works great, but I have to do a HTTP request with JQuery. It’d be wonderful if I could use the Websocket to call the service.