Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. MySensors Gatway dimmers & Home assistant

MySensors Gatway dimmers & Home assistant

Scheduled Pinned Locked Moved Hardware
21 Posts 4 Posters 4.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • enloE Offline
    enloE Offline
    enlo
    wrote on last edited by
    #7

    You should get rid of whiteLed (replace it with currentWhiteLevel). There is no need for two state variables for the same thing. I think they can even run out of sync, when the button is pressed while the message is processed.

    However, I am not really sure if they are responsible for your issue.

    Richard van der PlasR 1 Reply Last reply
    0
    • pansenP pansen

      I'm confused, your arduino node is connected to something via serial?

      Richard van der PlasR Offline
      Richard van der PlasR Offline
      Richard van der Plas
      wrote on last edited by
      #8

      @pansen yes the USB is connectec to my Raspberry pi which is running Home Assistant.
      over the USB connection the Mysensors messages are done .
      So when the Home assistant is running i have no access to the serial console.
      I Can serial print some things which will show up in the HASS log files as incorrect messages but thats not instant feedback

      1 Reply Last reply
      0
      • enloE enlo

        You should get rid of whiteLed (replace it with currentWhiteLevel). There is no need for two state variables for the same thing. I think they can even run out of sync, when the button is pressed while the message is processed.

        However, I am not really sure if they are responsible for your issue.

        Richard van der PlasR Offline
        Richard van der PlasR Offline
        Richard van der Plas
        wrote on last edited by
        #9

        @enlo i wil try that.

        martinhjelmareM 1 Reply Last reply
        0
        • Richard van der PlasR Richard van der Plas

          @enlo i wil try that.

          martinhjelmareM Offline
          martinhjelmareM Offline
          martinhjelmare
          Plugin Developer
          wrote on last edited by martinhjelmare
          #10

          @Richard-van-der-Plas

          Hi!

          If the light is not already on when you request a brightness change from home assistant, it will send a V_LIGHT message to turn the light on, to the device. The device will process that message in receive and this is an important line:

          requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
          

          It means that it will set requestedLevel to 100 if receiving a V_LIGHT message type. So it will reply home assistant with two messages. First a message of V_LIGHT to turn the light on, and then a message of V_DIMMER with payload 100.

          send(lightMsgWhite.set(currentWhiteLevel > 0));
          send(dimmerMsgWhite.set(currentWhiteLevel) );
          

          This is why the brightness always goes to 100 before being set to your requested value. It's only on the second message from home assistant that the light will actually turn to the requested brightness. This should not be the case if the light is already on, when requesting a new brightness. Then the brightness should change to the correct level directly.

          If you want to avoid the former behavior, you should decouple the replies to home assistant. Only answer a V_LIGHT message with a V_LIGHT message and only answer a V_DIMMER message with a V_DIMMER message.

          Edit:
          Caveat is that if not setting dimmer level and sending a V_DIMMER message when receiving the V_LIGHT message, the device will have the previous brightness setting until receiving the message with V_DIMMER and new level.

          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.

          Richard van der PlasR 1 Reply Last reply
          1
          • martinhjelmareM martinhjelmare

            @Richard-van-der-Plas

            Hi!

            If the light is not already on when you request a brightness change from home assistant, it will send a V_LIGHT message to turn the light on, to the device. The device will process that message in receive and this is an important line:

            requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
            

            It means that it will set requestedLevel to 100 if receiving a V_LIGHT message type. So it will reply home assistant with two messages. First a message of V_LIGHT to turn the light on, and then a message of V_DIMMER with payload 100.

            send(lightMsgWhite.set(currentWhiteLevel > 0));
            send(dimmerMsgWhite.set(currentWhiteLevel) );
            

            This is why the brightness always goes to 100 before being set to your requested value. It's only on the second message from home assistant that the light will actually turn to the requested brightness. This should not be the case if the light is already on, when requesting a new brightness. Then the brightness should change to the correct level directly.

            If you want to avoid the former behavior, you should decouple the replies to home assistant. Only answer a V_LIGHT message with a V_LIGHT message and only answer a V_DIMMER message with a V_DIMMER message.

            Edit:
            Caveat is that if not setting dimmer level and sending a V_DIMMER message when receiving the V_LIGHT message, the device will have the previous brightness setting until receiving the message with V_DIMMER and new level.

            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.

            Richard van der PlasR Offline
            Richard van der PlasR Offline
            Richard van der Plas
            wrote on last edited by
            #11

            @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 ?

            martinhjelmareM 1 Reply Last reply
            0
            • Richard van der PlasR Richard van der Plas

              @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 ?

              martinhjelmareM Offline
              martinhjelmareM Offline
              martinhjelmare
              Plugin Developer
              wrote on last edited by
              #12

              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.

              Richard van der PlasR 1 Reply Last reply
              0
              • martinhjelmareM martinhjelmare

                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.

                Richard van der PlasR Offline
                Richard van der PlasR Offline
                Richard van der Plas
                wrote on last edited by Richard van der Plas
                #13

                @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 ,

                1 Reply Last reply
                1
                • martinhjelmareM Offline
                  martinhjelmareM Offline
                  martinhjelmare
                  Plugin Developer
                  wrote on last edited by martinhjelmare
                  #14

                  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.

                  1 Reply Last reply
                  0
                  • Richard van der PlasR Offline
                    Richard van der PlasR Offline
                    Richard van der Plas
                    wrote on last edited by
                    #15

                    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 );
                    
                        }
                    
                    1 Reply Last reply
                    0
                    • martinhjelmareM Offline
                      martinhjelmareM Offline
                      martinhjelmare
                      Plugin Developer
                      wrote on last edited by
                      #16

                      But then how would you turn the light on without using the brightess slider in home assistant?

                      Richard van der PlasR 1 Reply Last reply
                      0
                      • martinhjelmareM martinhjelmare

                        But then how would you turn the light on without using the brightess slider in home assistant?

                        Richard van der PlasR Offline
                        Richard van der PlasR Offline
                        Richard van der Plas
                        wrote on last edited by Richard van der Plas
                        #17

                        @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 ???

                        1 Reply Last reply
                        0
                        • martinhjelmareM Offline
                          martinhjelmareM Offline
                          martinhjelmare
                          Plugin Developer
                          wrote on last edited by martinhjelmare
                          #18

                          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.

                          1 Reply Last reply
                          0
                          • Richard van der PlasR Offline
                            Richard van der PlasR Offline
                            Richard van der Plas
                            wrote on last edited by
                            #19

                            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 ?

                            1 Reply Last reply
                            0
                            • martinhjelmareM Offline
                              martinhjelmareM Offline
                              martinhjelmare
                              Plugin Developer
                              wrote on last edited by martinhjelmare
                              #20

                              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

                              Richard van der PlasR 1 Reply Last reply
                              0
                              • martinhjelmareM martinhjelmare

                                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

                                Richard van der PlasR Offline
                                Richard van der PlasR Offline
                                Richard van der Plas
                                wrote on last edited by
                                #21

                                @martinhjelmare Thanks for the input, when i arrive home ill update my code :)

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                18

                                Online

                                11.7k

                                Users

                                11.2k

                                Topics

                                113.1k

                                Posts


                                Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • MySensors
                                • OpenHardware.io
                                • Categories
                                • Recent
                                • Tags
                                • Popular