MySensors Gatway dimmers & Home assistant
-
@martinhjelmare How can i fix that, read your story twice, know what you mean, but don know the solution :)
i think i need to split
((message.type == V_LIGHT || message.type == V_DIMMER) && message.sensor==2)
is that correct ?Yes, exactly. Have one logic when receiving a V_LIGHT message and another logic when receiving a V_DIMMER message. I can post example code in a bit, currently on mobile.
-
Yes, exactly. Have one logic when receiving a V_LIGHT message and another logic when receiving a V_DIMMER message. I can post example code in a bit, currently on mobile.
@martinhjelmare ok ill wait,
meanwhile splitted the Message.type== V_LIGHT & == V_DIMMER into 2 different ifs.
created a quick serial.println on the vlight, and see in my HASS that indeed changing the dim level on the led when off , triggers a v_light and turns it to 100%
-Update indeed when removing the V_LIGHT message type behaviour is okay, but im unable to turn off the light- Following code is now testing:
if ((message.type == V_LIGHT) && message.sensor==1) { int requestedLevel = atoi( message.data ); Serial.print("message:"); Serial.println(requestedLevel); Serial.print("VLIGHT DETECTET set to:"); requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 ); Serial.println(requestedLevel); if (requestedLevel <1) {fadeWhiteToLevel( requestedLevel );} }Behaviour is better now
only issue i now have is the 255 values of arduino to the 100 of HASS , -
This should work, but I haven't tested it:
void receive(const MyMessage &message) { if ((message.type == V_LIGHT && message.sensor==1) { int lightState = message.getInt(); if (( lightState == 1 ) && ( currentWhiteLevel == 0 )) { requestedLevel = 100; } else { requestedLevel = lightState > 0 ? currentWhiteLevel : 0; } } if (message.type == V_DIMMER && message.sensor==1)) { int requestedLevel = message.getInt(); requestedLevel = requestedLevel > 100 ? 100 : requestedLevel; requestedLevel = requestedLevel < 0 ? 0 : requestedLevel; } whiteLed = requestedLevel; fadeWhiteToLevel( requestedLevel ); }Edit:
It's not really about decoupling the replies but about decoupling the logic that handles the incoming values and what actions to take for changing the dimmer. Sorry for being unclear above. -
i have fixed it like this :
void receive(const MyMessage &message) { if ((message.type == V_LIGHT)) { // V_LIGHT command received, only do something when 0 int requestedLevel = atoi( message.data ); if (requestedLevel ==0 && message.sensor == 1) {fadeWhiteToLevel( requestedLevel );} if (requestedLevel ==0 && message.sensor == 2) {fadeBlueToLevel( requestedLevel );} } if ((message.type == V_DIMMER) ) { // Retrieve the dim level from the incoming request message int requestedLevel = atoi( message.data ); // Clip incoming level to valid range of 0 to 100 requestedLevel = requestedLevel > 100 ? 100 : requestedLevel; requestedLevel = requestedLevel < 0 ? 0 : requestedLevel; if (message.sensor == 1) {fadeWhiteToLevel( requestedLevel );} if (message.sensor == 2) {fadeBlueToLevel( requestedLevel );} fadeBlueToLevel( requestedLevel ); } -
But then how would you turn the light on without using the brightess slider in home assistant?
-
But then how would you turn the light on without using the brightess slider in home assistant?
@martinhjelmare indeed that doesn't work anymore, i have to turn on the light with the slider.
But because its alwas an automation that turns on the light, that isnt such a big problem. i m trying to keep the code as small ass possible, because i have to add a dallas temperature controller to it, and its already complaining about low storage :(Sketch uses 10020 bytes (69%) of program storage space. Maximum is 14336 bytes. Global variables use 850 bytes (83%) of dynamic memory, leaving 174 bytes for local variables. Maximum is 1024 bytes.In your code i also see this line:
if (( lightState == 1 ) && ( currentWhiteLevel == 0 )) { requestedLevel = 100; } else { requestedLevel = lightState > 0 ? currentWhiteLevel : 0; }what does that do when light is on & level is 0 turn it to 100% else ???
-
If you request the light to turn on and current level is 0, we don't want the light to remain at 0 level, so we set it to 100 instead.
Edit:
I think you can save memory in other parts of your sketch, if you need. But you're not at 100% yet, so I wouldn't worry until I hit the limit. -
I understand your statement, but that's where it went wrong,
The hass also sends lights on when changing the dim value so it first goes to 100 ?
other question
Any idea how i can change the delta of 1 & -1 of 100% to 1 & -1 of 255 steps the arduino can cope ? -
We only set the level to 100 when current level is 0, otherwise we set to same level as current level.
Look at map function for remapping brightness.
https://www.arduino.cc/en/Reference/Map -
We only set the level to 100 when current level is 0, otherwise we set to same level as current level.
Look at map function for remapping brightness.
https://www.arduino.cc/en/Reference/Map@martinhjelmare Thanks for the input, when i arrive home ill update my code :)