Skip to content
  • 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
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

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.
  • 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


                      10

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2019 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
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular