# Homeyduino dim function problem

**URL:** <https://community.homey.app/t/homeyduino-dim-function-problem/34665>\
**Category:** Questions & Help\
**Created:** [September 13, 2020, 10:03pm UTC](https://community.homey.app/t/homeyduino-dim-function-problem/34665 "2020-09-13T22:03:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias\_Gunnarsson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mathias_gunnarsson/32/16342_2.png) [@Mathias\_Gunnarsson](https://community.homey.app/u/Mathias_Gunnarsson)\
**Post date:** [September 13, 2020, 10:03pm UTC](https://community.homey.app/t/homeyduino-dim-function-problem/34665/1 "2020-09-13T22:03:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [September 14, 2020, 11:54am UTC](https://community.homey.app/t/homeyduino-dim-function-problem/34665/2 "2020-09-14T11:54:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Mathias\_Gunnarsson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mathias_gunnarsson/32/16342_2.png) [@Mathias\_Gunnarsson](https://community.homey.app/u/Mathias_Gunnarsson)\
**Post date:** [September 15, 2020, 3:35pm UTC](https://community.homey.app/t/homeyduino-dim-function-problem/34665/3 "2020-09-15T15:35:30Z")

</div>

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

void setup()  
{  
Serial.begin(115200);  
pinMode(LED, OUTPUT);  
Homey.begin(“Jysk3”);  
Homey.setClass(“light”);  
Homey.addCapability(“onoff”, setState);  
Homey.addCapability(“dim”, setDim);  
Homey.addAction(“LED”, setState);  
Homey.addAction(“DIM\_LED”, setDim);  
Homey.addCondition(“state”, getState);  
[//Homey.addCondition](https://Homey.addCondition)(“dim”, getDim);

}  
//-----------------------------------------------------------------------  
void loop()  
{  
Homey.loop();  
}  
//-----------------------------------------------------------------------  
void setState() {  
state = Homey.value.toInt();  
applyState();  
}

void setDim()  
{  
dim\_level = Homey.value.toFloat();  
dim\_level = map (dim\_level, 0.00, 1.00, 0, 255);  
Serial.println(dim\_level);  
applyDim();  
}

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);  
}

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [September 15, 2020, 4:18pm UTC](https://community.homey.app/t/homeyduino-dim-function-problem/34665/4 "2020-09-15T16:18:08Z")

</div>

> [@Mathias\_Gunnarsson](#):
>
> dim\_level = map (dim\_level, 0.00, 1.00, 0, 255);

[https://www.arduino.cc/reference/en/language/functions/math/map/:](https://www.arduino.cc/reference/en/language/functions/math/map/:)

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

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

---

<div class="post-metadata">

**Author:** ![Mathias\_Gunnarsson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mathias_gunnarsson/32/16342_2.png) [@Mathias\_Gunnarsson](https://community.homey.app/u/Mathias_Gunnarsson)\
**Post date:** [September 15, 2020, 4:46pm UTC](https://community.homey.app/t/homeyduino-dim-function-problem/34665/5 "2020-09-15T16:46:27Z")

</div>

Thanks a lot!!! That did the trick!

---

<div class="post-metadata">

**Author:** ![RobertW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertw/32/29891_2.png) [@RobertW](https://community.homey.app/u/RobertW)\
**Post date:** [October 18, 2020, 1:08pm UTC](https://community.homey.app/t/homeyduino-dim-function-problem/34665/6 "2020-10-18T13:08:59Z")

</div>

Hi, Can you share the full working code?
