Closed sebkouba closed 3 years ago
Hi @sebkouba what you are setting is value in percent (0 to 100); on code site you have 8 Bit so it is 0 to 255. Which means setting to 50 (%) means arrive of value 127.
If you want that value back, the map method in arduino framework is easy to use for that purpose. https://www.arduino.cc/reference/en/language/functions/math/map/
fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
int val = map(value, 0, 255, 0, 100);
Serial.println("value: " + String(val));
});
Thanks Jorgen! That's really helpful. Good explanation and elegant solution :)
First off, I love this library. It has made it really easy to get started with my esp8266 and alexa which is a lot of fun.
I'm still poking around, especially in onSetState. It seems that setting a value is possible between 1 and 100 which returns values between 2 and 255. When I say "turn device to 50" the value I expected was 50 but what I get is 127. I'm guessing it's related to how colours work. In the readme it seems that the expected behaviour is getting returned the number you set. Am I missing something?
I get what I thought was the intended behaviour using this:
The only exception is 100, which returns 101 :| Maybe use math.h and round?
Cheers