Homey Community Forum

Homeyduino dim function problem

Hi! I have a problem when using Homeyduino and using dim capibility. When I use the function Homey.value.toFloat(); It only sends me back 0.00 or 1.00. When I adjust the dimmer in the Homey app I can see it sends a new value every time only it’s always 0.00 until i drag the dimmer to the top and it sends me 1.00. Does anyone now what I’m doing wrong?

Hi Mathias, welcome to this community forum.
Can you please show the relevant peace of your code, how else can we see what is wrong?

Yes of course sorry. Wrote on my phone and didn’t have the code.

void setup()
pinMode(LED, OUTPUT);
Homey.addCapability(“onoff”, setState);
Homey.addCapability(“dim”, setDim);
Homey.addAction(“LED”, setState);
Homey.addAction(“DIM_LED”, setDim);
Homey.addCondition(“state”, getState);
//Homey.addCondition(“dim”, getDim);

void loop()
void setState() {
state = Homey.value.toInt();

void setDim()
dim_level = Homey.value.toFloat();
dim_level = map (dim_level, 0.00, 1.00, 0, 255);

void applyState() {
digitalWrite(LED, state);
Homey.setCapabilityValue(“onoff”, state);
Homey.trigger(“state”, state);

void applyDim(){
analogWrite(LED, dim_level);
Homey.setCapabilityValue(“dim”, dim_level);
Homey.trigger(“dim_level”, dim_level);

void getState() {
Serial.println("getState(): state is "+String(state));
return Homey.returnResult(state);


As previously mentioned, the map() function uses integer math.

So you need to write your own mapping function that can handle floats.

1 Like

Thanks a lot!!! That did the trick!

1 Like