Homey Community Forum

Homey and Arduino

I have gotten the Arduino MKR WiFi 1010 to work with HomeyArduino app.

I have a stable connection and I can change capabilities from Homey on the Arduino board. I can execute actions and check conditions. But I have one problem…

I can not synchronize the state of the Arduino board on power cycle or reset. I have a sync function that contains this

Homey.setCapabilityValue(“onoff”,s_state,true);
Homey.setCapabilityValue(“dim”,s_intensity);
Homey.setCapabilityValue(“light_hue”,s_hue);
Homey.setCapabilityValue(“light_saturation”,s_saturation);

This is called from the setup function in the Arduino sketch, after Homey is initialized as follows:

Homey.begin(“AnimLED-C414”);
Homey.setClass(“light”);

Homey.addCapability(“onoff”, setStateCallback);
Homey.addCapability(“dim”, IntensityCallback);
Homey.addCapability(“light_hue”, HueCallback);
Homey.addCapability(“light_saturation”, SaturationCallback);

Homey.addCondition(“state”, getStateCallback);

I can get “dim”, “light_hue” and “light_saturation” to work if I spend som 10 seconds calling Homey.loop() and then sync, how ever “onoff” does not work. It would be kind of nice if I can get it to work and without the 10 sec delay.

Any solutions are welcome!

Thanks in advance!

Perhaps this works:

Homey.setCapabilityValue("onoff",s_state,true);
Homey.setCapabilityValue("onoff",s_state);
Homey.setCapabilityValue("dim",s_intensity, true);
Homey.setCapabilityValue("dim",s_intensity);
Homey.setCapabilityValue("light_hue",s_hue, true);
Homey.setCapabilityValue("light_hue",s_hue);
Homey.setCapabilityValue("light_saturation",s_saturation, true);
Homey.setCapabilityValue("light_saturation",s_saturation);

Which, from the source, seems to be equivalent to:

Homey.emit("onoff", s_state);
Homey.setCapabilityValue("onoff", s_state);
Homey.emit("dim", s_intensity);
Homey.setCapabilityValue("dim", s_intensity);
Homey.emit("light_hue", s_hue);
Homey.setCapabilityValue("light_hue", s_hue);
Homey.emit("light_saturation", s_saturation);
Homey.setCapabilityValue("light_saturation", s_saturation);