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. Controllers
  3. Home Assistant
  4. Home Assistant - How to recognize MySensors nodes

Home Assistant - How to recognize MySensors nodes

Scheduled Pinned Locked Moved Home Assistant
home assistant
64 Posts 7 Posters 46.1k 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.
  • martinhjelmareM Offline
    martinhjelmareM Offline
    martinhjelmare
    Plugin Developer
    wrote on last edited by
    #12

    Have you activated (uncommented) DEBUG in MyConfig.h?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      humblehacker
      wrote on last edited by humblehacker
      #13

      As I keep my sketchbook synchronized through Github, I can confirm that debugging is enabled in my master here
      However, I will need to confirm that the local sketchbook on the laptop I was using yesterday is up to date with the remote master. I'm pretty sure I enabled debugging when I first installed it.

      EDIT- Isn't debugging enabled by default now?- https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MyConfig.h

      martinhjelmareM 1 Reply Last reply
      0
      • A Offline
        A Offline
        acmbc68
        wrote on last edited by
        #14

        Hi,

        I've been following this thread for a few days, as I am in the same situation and kielnino - I can see the MySensors component get loaded and then....silence....I know the MySensors GW and nodes are working from testing with serial monitors and another controller app (MySController).

        Will probably be spending some time tracing through the pymysensors code tonight to see what gives. I do have debug enabled on homeassistant, but still no joy.

        One thought - shouldn't MySensors on homeassistant be implemented as a platform (and not a sensor) much like MQTT.

        I have got readings to work through MQTT (in my case, patched a node-red flow together to read the serial line and publish to a local mosquitto), but this is like driving around the city to get to the store next door...

        Any further thoughts/hints as to where to start looking?

        Thanks!

        martinhjelmareM 1 Reply Last reply
        0
        • H humblehacker

          As I keep my sketchbook synchronized through Github, I can confirm that debugging is enabled in my master here
          However, I will need to confirm that the local sketchbook on the laptop I was using yesterday is up to date with the remote master. I'm pretty sure I enabled debugging when I first installed it.

          EDIT- Isn't debugging enabled by default now?- https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MyConfig.h

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

          @humblehacker

          Yes, it should be enabled by default, that's why I didn't mention it in my first advice. But it's good to double check anyway.

          Are you sure you have two different instances of the Arduino IDE running when you test? Only one serial monitor can be active at a time, per IDE. It's not enough to open a second sketch window. You have to start the IDE twice from the start menu, or however you start it. Also, check the ports. You should see different headings in the serial monitor window, specifying the port.

          What hardware are you using?

          H 1 Reply Last reply
          0
          • A acmbc68

            Hi,

            I've been following this thread for a few days, as I am in the same situation and kielnino - I can see the MySensors component get loaded and then....silence....I know the MySensors GW and nodes are working from testing with serial monitors and another controller app (MySController).

            Will probably be spending some time tracing through the pymysensors code tonight to see what gives. I do have debug enabled on homeassistant, but still no joy.

            One thought - shouldn't MySensors on homeassistant be implemented as a platform (and not a sensor) much like MQTT.

            I have got readings to work through MQTT (in my case, patched a node-red flow together to read the serial line and publish to a local mosquitto), but this is like driving around the city to get to the store next door...

            Any further thoughts/hints as to where to start looking?

            Thanks!

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

            @acmbc68

            Hi!

            Regarding the current mysensors implementation in home assistant, it's a sensor platform. But it's not a separate component.

            I have added a mysensors component together with a switch platform, in my github fork of home assistant. I haven't made a pull request yet, cause I'm waiting to have my other pull request to pymysensors approved, where I implement support for setting child values from the controller, cause it's a dependency.

            https://github.com/MartinHjelmare/home-assistant/tree/mysensors-component-switch

            https://github.com/MartinHjelmare/pymysensors/tree/fifo_queue

            I'm not completely finished with the home assistant switch branch. I want to add support for multiple gateways as well, and I haven't had time to test my solution properly yet.

            I've added more debug logging in my fifo_queue branch of pymysensors, and made the serial connection more robust, by closing it when the thread quits. I've also downgraded the required pyserial version to 2.5, due to a bug in pyserial 2.6 - 3. This has been fixed in the master branch of pyserial, but no new release exists, I think.

            If you know how to change installed components in home assistant, you can give my branches a try. They should be working in their current state on github, but more testing is always good.

            When I first started testing connecting my node with the gateway and home assistant, I had problems in the beginning, When I set the node id to 1 and made sure at least one value was sent from the node, I got it working. It might have been a coincidence, that it started working then, cause I'm not sure that home assistant needs sequential entity ids, but when you're debugging it's good to narrow down possible variables/problems. You also have to make sure that the gateway receives all the presentation data, including sketch name, from the node. Otherwise the sensor won't show up in the GUI. That's currently how it's written in the code.

            Edit:
            One more thing. Even though debug level logging should be enabled by default in home assistant 0.8, you still have to enable the logger component in your config.
            https://home-assistant.io/components/logger/

            1 Reply Last reply
            0
            • A Offline
              A Offline
              acmbc68
              wrote on last edited by
              #17

              Thanks @martinhjelmare

              As per https://home-assistant.io/blog/posts/2/, all the components should be under the homeassistant install, so it shouldn't be a brain-wrecker to change those out.

              I'll start giving it a whirl tonight.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                acmbc68
                wrote on last edited by
                #18

                Ok.
                First of all - still no joy. Can't get any communications from MySensors to homeassistant.

                Trying to tackle this bottom up. Thought it might be an issue with PySerial, but that reads data OK from the serial port:

                import serial as serial
                print ("starting")
                ser = serial.Serial (
                    port='COM4',
                    baudrate=115200,
                    parity=serial.PARITY_NONE,
                    stopbits=serial.STOPBITS_ONE,
                    bytesize=serial.EIGHTBITS
                )
                
                ser.flushInput()
                ser.flushOutput()
                
                print("connected to: " + ser.portstr)
                count=1
                
                while True:
                        try:
                                data_raw = ser.readline()
                                print(data_raw)
                        except serial.SerialException:
                                print ("SERIAL ERROR")
                                exit(1)
                

                This results in what is expected:

                starting
                connected to: COM4
                b'0;0;3;0;14;Gateway startup complete.\n'
                b'0;0;3;0;9;read: 1-1-0 s=2,c=1,t=23,pt=2,l=2:0\n'
                b'1;2;1;0;23;0\n'
                b'0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5:25.0\n'
                b'1;1;1;0;0;25.0\n'
                b'0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5:84.0\n'
                b'1;0;1;0;1;84.0\n'
                b'0;0;3;0;9;read: 1-1-0 s=3,c=1,t=16,pt=0,l=1:0\n'
                b'1;3;1;0;16;0\n'
                

                (this is a four sensor node - Temp, Humidity, light level and presence detection)

                I am trying to test the pymysensors (mysensors.mysensors) and I believe that is where the situation may originate.

                Basically, pymysensors just hangs there on calling gw.start() in the code below:

                
                import mysensors.mysensors as mysensors
                import logging
                
                def event(type, nid):
                    print(type+" "+str(nid))
                
                gw = mysensors.SerialGateway('COM4', event)
                logging.warning("Created SerialGateway")
                print (gw)
                gw.start()
                

                Trying to wrangle through the pymysensors code...Could it be the windows threading implementation (gw.start()) causing some type of hung access to the serial port? Unfortunately, no messages (print or logging) that I put in the pymysensors actually get printed out (maybe due to being in a background thread?

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

                  For logging to work you have to set the level lower, and you should activate debug mode in pymysensors.

                  import mysensors.mysensors as mysensors
                  import logging
                  
                  logging.basicConfig(level=logging.DEBUG)
                  
                  def event(type, nid):
                      print(type+" "+str(nid))
                  
                  gw = mysensors.SerialGateway('COM4', event)
                  logging.warning("Created SerialGateway")
                  print (gw)
                  
                  gw.debug = True
                  
                  gw.start()
                  

                  This is my console log when testing my fifo_queue branch.

                  In [1]: %paste
                  import mysensors.mysensors as mysensors
                  import logging
                  
                  logging.basicConfig(level=logging.DEBUG)
                  
                  def event(type, nid):
                      print(type+" "+str(nid))
                  
                  ## -- End pasted text --
                  
                  In [2]: gw = mysensors.SerialGateway('/dev/ttyUSB0', event)
                  
                  In [3]: gw.debug = True
                  
                  In [4]: gw.start()
                  INFO:mysensors.mysensors:Trying to connect to /dev/ttyUSB0
                  
                  In [5]: INFO:mysensors.mysensors:/dev/ttyUSB0 is open...
                  INFO:mysensors.mysensors:Connected to /dev/ttyUSB0
                  INFO:mysensors.mysensors:n:0 c:0 t:3 s:9 p:gateway started, id=0, parent=0, distance=0
                  
                  KeyboardInterrupt
                  
                  In [5]: gw.stop()
                  INFO:mysensors.mysensors:Disconnecting from /dev/ttyUSB0
                  INFO:mysensors.mysensors:Stopping thread
                  

                  Sometimes I get the following problem when I start the thread:

                  WARNING:mysensors.mysensors:Error decoding message from gateway, probably received bad byte.
                  

                  A new gateway instance and restarting it always solves that. Sometimes messages seem to go out of sync, then it can be good to reconnect power to the gateway, also. But that has been very rare:

                  Exception in thread Thread-1:
                  Traceback (most recent call last):
                    File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
                      self.run()
                    File "/home/martin/Dev/pymysensors/mysensors/mysensors.py", line 312, in run
                      response = self.handle_queue()
                    File "/home/martin/Dev/pymysensors/mysensors/mysensors.py", line 222, in handle_queue
                      reply = func(*args, **kwargs)
                    File "/home/martin/Dev/pymysensors/mysensors/mysensors.py", line 105, in logic
                      msg = Message(data)
                    File "/home/martin/Dev/pymysensors/mysensors/mysensors.py", line 397, in __init__
                      self.decode(data)
                    File "/home/martin/Dev/pymysensors/mysensors/mysensors.py", line 417, in decode
                      self.sub_type) = [int(f) for f in data]
                    File "/home/martin/Dev/pymysensors/mysensors/mysensors.py", line 417, in <listcomp>
                      self.sub_type) = [int(f) for f in data]
                  ValueError: invalid literal for int() with base 10: 'read: 1-1-0 s=1,c=1,t=0'
                  
                  1 Reply Last reply
                  0
                  • martinhjelmareM martinhjelmare

                    @humblehacker

                    Yes, it should be enabled by default, that's why I didn't mention it in my first advice. But it's good to double check anyway.

                    Are you sure you have two different instances of the Arduino IDE running when you test? Only one serial monitor can be active at a time, per IDE. It's not enough to open a second sketch window. You have to start the IDE twice from the start menu, or however you start it. Also, check the ports. You should see different headings in the serial monitor window, specifying the port.

                    What hardware are you using?

                    H Offline
                    H Offline
                    humblehacker
                    wrote on last edited by
                    #20

                    @martinhjelmare said:

                    @humblehacker

                    Yes, it should be enabled by default, that's why I didn't mention it in my first advice. But it's good to double check anyway.

                    Are you sure you have two different instances of the Arduino IDE running when you test? Only one serial monitor can be active at a time, per IDE. It's not enough to open a second sketch window. You have to start the IDE twice from the start menu, or however you start it. Also, check the ports. You should see different headings in the serial monitor window, specifying the port.

                    What hardware are you using?

                    I had replied to this a couple days ago but it must not have posted so I apologize for the tardy response...
                    I think I might've narrowed down to what my problem is but first I'll reply to your question. My first test used two different instances of the IDE running on two different systems.
                    The gateway controller sketch was compiled on Windows 10 w/Arduino 1.6.6 and ran successfully on an Arduino UNO. The sensor/sender sketch was compiled on my Ubuntu MATE 15.10 laptop with Arduino 1.6.6 on an Arduino Leonardo.

                    Interestingly, I just tried swapping out the hardware so the Uno connected to Linux and the Leo connected to Windows. Sure enough, the Uno works as expected running both the sensor and the gateway sketch on Linux and Windows while the Leo won't work with any MySensors sketch on either Linux or Windows... So the problem may be related to the serial port on the ATMega32u4. As I mentioned earlier, I was able to get the Leo to work with the standard RF24 library, so it must be something about the Mysensors library that doesn't get along with the ATMega32u4 processors...
                    I'll try running my Arduino Nano now to see if it works with signals sent from my Uno.

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      humblehacker
                      wrote on last edited by
                      #21

                      UPDATE:
                      YES!!! The Uno connected to the motion sensor is transmitting data to my Arduino Nano gateway and I can finally see the data on the serial monitor! Now I just need to reconnect the gateway to Home Assistant to see what it picks up.
                      Lesson learned as of the present is to only use ATMega328 processors like the Uno, Nano, Pro Mini etc... Most of my controllers at this point are based on the 32u4 so it would be good if we could figure out why the Leo boards don't work with MYS... Has anybody else experienced this problem?

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        humblehacker
                        wrote on last edited by
                        #22

                        Sure enough-

                        WARNING:mysensors.mysensors:Error decoding message from gateway, probably received bad byte.
                        

                        @martinhjelmare- How do I create a new gateway instance? Simply restart?

                        martinhjelmareM 1 Reply Last reply
                        0
                        • H humblehacker

                          Sure enough-

                          WARNING:mysensors.mysensors:Error decoding message from gateway, probably received bad byte.
                          

                          @martinhjelmare- How do I create a new gateway instance? Simply restart?

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

                          @humblehacker

                          If using home assistant, it's enough to restart home assistant, to get a new gateway instance and reconnect.

                          1 Reply Last reply
                          0
                          • H Offline
                            H Offline
                            humblehacker
                            wrote on last edited by
                            #24

                            success!.png
                            :smiley:
                            Other than the fact that my log seems to think its yesterday... I just need to find out why I can't use MySensors with Any ATMega32u4 devices... Attiny85/Trinket support would be nice too but I dont need to push my luck...

                            martinhjelmareM 1 Reply Last reply
                            0
                            • H humblehacker

                              success!.png
                              :smiley:
                              Other than the fact that my log seems to think its yesterday... I just need to find out why I can't use MySensors with Any ATMega32u4 devices... Attiny85/Trinket support would be nice too but I dont need to push my luck...

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

                              @humblehacker

                              :thumbsup:

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                kielnino
                                wrote on last edited by
                                #26

                                I'm still stuck with the import of sensors to home-assitant. Can someone please post his configuration.yaml? I Wonder if I made a stupid configuration error there.
                                Do I need the "inclusion mode" of the Gateway or does home-assistant handle the detection of new sensors? In the serial monitor all the communication between the nodes and the Gateway is looking good, but in home-assistant they won't show up.

                                martinhjelmareM 1 Reply Last reply
                                0
                                • K kielnino

                                  I'm still stuck with the import of sensors to home-assitant. Can someone please post his configuration.yaml? I Wonder if I made a stupid configuration error there.
                                  Do I need the "inclusion mode" of the Gateway or does home-assistant handle the detection of new sensors? In the serial monitor all the communication between the nodes and the Gateway is looking good, but in home-assistant they won't show up.

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

                                  @kielnino

                                  Home assistant adds the new device after the sensor has presented itself to the gateway and sent at least one value. So proper presentation messages has to be sent by the node and received by the gateway. These include node id, sensor child id, sketch name and presentation "S_VALUE". Then one value should be sent using the correct "V_VALUE".

                                  See the mysensor API documentation for the S_VALUES and V_VALUES.

                                  See below for the sensors excerpt from my config. If you have multiple sensor platforms you need to increment the sensor name with a number: sensor, sensor 2, sensor 3, etc. All sensor platforms should be one continuing block in the config. Note that this is not my config for my github fork of home assistant. For that one, you need to add a separate domain in the config for mysensors.

                                  ###########################################################
                                  # SENSORS
                                  ###########################################################
                                  
                                  # Mysensors
                                  sensor:
                                    platform: mysensors
                                    port: "/dev/ttyUSB0"
                                  #  debug:
                                  
                                  # forecast.io
                                  sensor 2:
                                    platform: forecast
                                    api_key: ***censored***
                                    monitored_conditions:
                                      - summary
                                      - precip_type
                                      - precip_intensity
                                      - temperature
                                      - dew_point
                                      - wind_speed
                                      - wind_bearing
                                      - cloud_cover
                                      - humidity
                                      - pressure
                                      - visibility
                                      - ozone
                                  
                                  # time_date
                                  sensor 3:
                                    platform: time_date
                                    display_options:
                                      - 'time'
                                      - 'date'
                                      - 'date_time'
                                      - 'time_date'
                                      - 'time_utc'
                                      - 'beat'
                                  
                                  1 Reply Last reply
                                  0
                                  • D Offline
                                    D Offline
                                    drock1985
                                    wrote on last edited by
                                    #28

                                    Hi @martinhjelmare

                                    Just wanted to first say thank you for the port of MySensors to Home-Assistant. I'm currently in the process of switching from Domoticz to Home-Assistant, and have a quick question about getting my node recognized.

                                    I have a Doorbell/Chome monitor, and it gets the ID from the gateway no problem. It shows up in HA after pressing the doorbell button (as a motion sensor, since that is the trigger) but I can't control the chime itself (aka, whether the bell rings if the door is pressed or not) which is set as a light switch.

                                    I know from reading this thread that in order for a device to first appear in HA, it must send a command to the gateway. Is there any way for me through HA to force a command to the childid light switch, so that it will show up on its own?

                                    Thanks!

                                    My Projects
                                    2 Door Chime Sensor
                                    Washing Machine Monitor

                                    martinhjelmareM 1 Reply Last reply
                                    0
                                    • D drock1985

                                      Hi @martinhjelmare

                                      Just wanted to first say thank you for the port of MySensors to Home-Assistant. I'm currently in the process of switching from Domoticz to Home-Assistant, and have a quick question about getting my node recognized.

                                      I have a Doorbell/Chome monitor, and it gets the ID from the gateway no problem. It shows up in HA after pressing the doorbell button (as a motion sensor, since that is the trigger) but I can't control the chime itself (aka, whether the bell rings if the door is pressed or not) which is set as a light switch.

                                      I know from reading this thread that in order for a device to first appear in HA, it must send a command to the gateway. Is there any way for me through HA to force a command to the childid light switch, so that it will show up on its own?

                                      Thanks!

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

                                      @drock1985

                                      Hi!

                                      First I'd just want to make clear that I'm not the original author or maintainer of pymysensors, which is the mysensors API that home assistant uses. I have just made some pull requests to pymysensors and I'd like to improve the functionality, if possible.

                                      To answer your question, mysensors switches are not yet supported in home assistant. That's what one of my pull requests want to solve, but it has yet to be merged. There is currently no way of forcing a node to resend it's presentation, if that info is lacking on the gateway side. This could be solved after version 1.6 of mysensors gets released but it will take more development, both on pymysensors and home assistant sides.

                                      If you want to make sure that the doorbell shows up in the GUI, before the first press of the button, just send the sensor value to the gateway, in the end of the setup function in your node sketch.

                                      For example, if you have defined a msgMotion for the doorbell:

                                      gw.send(msgMotion.set("0"));
                                      
                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        drock1985
                                        wrote on last edited by
                                        #30

                                        Hi @martinhjelmare

                                        I decided to try this on a simplier sketch that I have, but still no luck. I added this line gw.send(lightMsgW.set("1")); to the end of void setup(). The sensor shows up at the top of the States screen in HA, but doesn't let me actually control it, and it doesn't show up in Switches or Lights.

                                        Here is the sketch that I am using.

                                        /**
                                         * The MySensors Arduino library handles the wireless radio link and protocol
                                         * between your home built sensors/actuators and HA controller of choice.
                                         * The sensors forms a self healing radio network with optional repeaters. Each
                                         * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                         * network topology allowing messages to be routed to nodes.
                                         *
                                         * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                         * Copyright (C) 2013-2015 Sensnology AB
                                         * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                         *
                                         * Documentation: http://www.mysensors.org
                                         * Support Forum: http://forum.mysensors.org
                                         *
                                         * This program is free software; you can redistribute it and/or
                                         * modify it under the terms of the GNU General Public License
                                         * version 2 as published by the Free Software Foundation.
                                         *
                                         *******************************
                                         *
                                         * REVISION HISTORY
                                         * Version 1.0 - 6-December-2015, Derrick Rockwell
                                         *
                                         * DESCRIPTION
                                         *This sketch uses two 30 bulb, 3mm LED holiday light strings. These
                                         *can usually be found in most dollar stores/hardware stores and are 
                                         *battery powered. This sketch uses digital pins 3 and 4 to power two 
                                         *a string of lights each. Ex, one can control white lights the other
                                         *could control multi-colour lights. 
                                         */
                                        
                                        #define SN "HolidayLEDDeskLights"
                                        #define SV "1.0"
                                        
                                        #include <MySensor.h> 
                                        #include <SPI.h>
                                        
                                        #define MLED_PIN 3      // Pin Multi-Coloured LED's will attached to
                                        #define WLED_PIN 5      // Pin White-Coloured LED's will attached to
                                        #define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
                                        #define CHILD_ID0 3
                                        #define CHILD_ID1 5
                                        
                                        MySensor gw;
                                        
                                        static int currentLevelM = 0;  // Current dim level...
                                        static int currentLevelW = 0;  // Current dim level...
                                        
                                        MyMessage dimmerMsgM(MLED_PIN, V_DIMMER);
                                        MyMessage lightMsgM(MLED_PIN, V_LIGHT);
                                        MyMessage dimmerMsgW(WLED_PIN, V_DIMMER);
                                        MyMessage lightMsgW(WLED_PIN, V_LIGHT);
                                        
                                        /***
                                         * Dimmable LED initialization method
                                         */
                                        void setup()  
                                        { 
                                          Serial.println( SN ); 
                                          Serial.println( SV );
                                          gw.begin( incomingMessage );
                                          
                                          // Register the LED Dimmable Light with the gateway
                                          gw.present( MLED_PIN, S_DIMMER );
                                          gw.present( WLED_PIN, S_DIMMER );
                                          
                                          gw.sendSketchInfo(SN, SV);
                                          // Pull the gateway's current dim level - restore light level upon sendor node power-up
                                          gw.request( MLED_PIN, V_DIMMER );
                                          gw.request( WLED_PIN, V_DIMMER );
                                          gw.send(lightMsgW.set("1"));
                                        }
                                        
                                        /***
                                         *  Dimmable LED main processing loop 
                                         */
                                        void loop() 
                                        {
                                          gw.process();
                                        }
                                        
                                        //For Multi Coloured Lights
                                        void incomingMessage(const MyMessage &message) {
                                        if (message.type == V_LIGHT || message.type == V_DIMMER) {
                                              // if (message.sensor <= 2)
                                              {
                                                  //0: All Dimmers
                                                  //1: LED 1
                                                  //2: LED 2
                                                  //  Retrieve the power or dim level from the incoming request message
                                                  int requestedLevel = atoi( message.data );
                                                  
                                                  // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
                                                  requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
                                                  
                                                  if ((message.sensor == CHILD_ID0) || (message.sensor == 0)){
                                                    fadeToLevel ( requestedLevel, MLED_PIN, &currentLevelM );
                                                    // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
                                                    gw.send(lightMsgM.set(requestedLevel > 0 ? 1 : 0));
                                                    gw.send(dimmerMsgM.set(requestedLevel) );
                                                  }
                                                  if ((message.sensor == CHILD_ID1) || (message.sensor == 0)){
                                                    fadeToLevel( requestedLevel, WLED_PIN, &currentLevelW );
                                                    // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
                                                    gw.send(lightMsgW.set(requestedLevel > 0 ? 1 : 0));
                                                    gw.send(dimmerMsgW.set(requestedLevel) );
                                                  }
                                                }
                                        }
                                        }
                                        
                                        /***
                                         *  This method provides a graceful fade up/down effect
                                         */
                                         // For Multi Coloured Lights
                                        void fadeToLevel( int toLevel, int pin, int *currentLevel ) {
                                          int delta = ( toLevel - (*currentLevel) ) < 0 ? -1 : 1;
                                          while ( (*currentLevel) != toLevel ) {
                                            (*currentLevel) += delta;
                                            analogWrite( pin, (int)((*currentLevel) / 100. * 255) );
                                            delay( FADE_DELAY );
                                          }
                                        }
                                        

                                        My Projects
                                        2 Door Chime Sensor
                                        Washing Machine Monitor

                                        martinhjelmareM H 2 Replies Last reply
                                        0
                                        • D drock1985

                                          Hi @martinhjelmare

                                          I decided to try this on a simplier sketch that I have, but still no luck. I added this line gw.send(lightMsgW.set("1")); to the end of void setup(). The sensor shows up at the top of the States screen in HA, but doesn't let me actually control it, and it doesn't show up in Switches or Lights.

                                          Here is the sketch that I am using.

                                          /**
                                           * The MySensors Arduino library handles the wireless radio link and protocol
                                           * between your home built sensors/actuators and HA controller of choice.
                                           * The sensors forms a self healing radio network with optional repeaters. Each
                                           * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                           * network topology allowing messages to be routed to nodes.
                                           *
                                           * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                           * Copyright (C) 2013-2015 Sensnology AB
                                           * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                           *
                                           * Documentation: http://www.mysensors.org
                                           * Support Forum: http://forum.mysensors.org
                                           *
                                           * This program is free software; you can redistribute it and/or
                                           * modify it under the terms of the GNU General Public License
                                           * version 2 as published by the Free Software Foundation.
                                           *
                                           *******************************
                                           *
                                           * REVISION HISTORY
                                           * Version 1.0 - 6-December-2015, Derrick Rockwell
                                           *
                                           * DESCRIPTION
                                           *This sketch uses two 30 bulb, 3mm LED holiday light strings. These
                                           *can usually be found in most dollar stores/hardware stores and are 
                                           *battery powered. This sketch uses digital pins 3 and 4 to power two 
                                           *a string of lights each. Ex, one can control white lights the other
                                           *could control multi-colour lights. 
                                           */
                                          
                                          #define SN "HolidayLEDDeskLights"
                                          #define SV "1.0"
                                          
                                          #include <MySensor.h> 
                                          #include <SPI.h>
                                          
                                          #define MLED_PIN 3      // Pin Multi-Coloured LED's will attached to
                                          #define WLED_PIN 5      // Pin White-Coloured LED's will attached to
                                          #define FADE_DELAY 10  // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
                                          #define CHILD_ID0 3
                                          #define CHILD_ID1 5
                                          
                                          MySensor gw;
                                          
                                          static int currentLevelM = 0;  // Current dim level...
                                          static int currentLevelW = 0;  // Current dim level...
                                          
                                          MyMessage dimmerMsgM(MLED_PIN, V_DIMMER);
                                          MyMessage lightMsgM(MLED_PIN, V_LIGHT);
                                          MyMessage dimmerMsgW(WLED_PIN, V_DIMMER);
                                          MyMessage lightMsgW(WLED_PIN, V_LIGHT);
                                          
                                          /***
                                           * Dimmable LED initialization method
                                           */
                                          void setup()  
                                          { 
                                            Serial.println( SN ); 
                                            Serial.println( SV );
                                            gw.begin( incomingMessage );
                                            
                                            // Register the LED Dimmable Light with the gateway
                                            gw.present( MLED_PIN, S_DIMMER );
                                            gw.present( WLED_PIN, S_DIMMER );
                                            
                                            gw.sendSketchInfo(SN, SV);
                                            // Pull the gateway's current dim level - restore light level upon sendor node power-up
                                            gw.request( MLED_PIN, V_DIMMER );
                                            gw.request( WLED_PIN, V_DIMMER );
                                            gw.send(lightMsgW.set("1"));
                                          }
                                          
                                          /***
                                           *  Dimmable LED main processing loop 
                                           */
                                          void loop() 
                                          {
                                            gw.process();
                                          }
                                          
                                          //For Multi Coloured Lights
                                          void incomingMessage(const MyMessage &message) {
                                          if (message.type == V_LIGHT || message.type == V_DIMMER) {
                                                // if (message.sensor <= 2)
                                                {
                                                    //0: All Dimmers
                                                    //1: LED 1
                                                    //2: LED 2
                                                    //  Retrieve the power or dim level from the incoming request message
                                                    int requestedLevel = atoi( message.data );
                                                    
                                                    // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
                                                    requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
                                                    
                                                    if ((message.sensor == CHILD_ID0) || (message.sensor == 0)){
                                                      fadeToLevel ( requestedLevel, MLED_PIN, &currentLevelM );
                                                      // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
                                                      gw.send(lightMsgM.set(requestedLevel > 0 ? 1 : 0));
                                                      gw.send(dimmerMsgM.set(requestedLevel) );
                                                    }
                                                    if ((message.sensor == CHILD_ID1) || (message.sensor == 0)){
                                                      fadeToLevel( requestedLevel, WLED_PIN, &currentLevelW );
                                                      // Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
                                                      gw.send(lightMsgW.set(requestedLevel > 0 ? 1 : 0));
                                                      gw.send(dimmerMsgW.set(requestedLevel) );
                                                    }
                                                  }
                                          }
                                          }
                                          
                                          /***
                                           *  This method provides a graceful fade up/down effect
                                           */
                                           // For Multi Coloured Lights
                                          void fadeToLevel( int toLevel, int pin, int *currentLevel ) {
                                            int delta = ( toLevel - (*currentLevel) ) < 0 ? -1 : 1;
                                            while ( (*currentLevel) != toLevel ) {
                                              (*currentLevel) += delta;
                                              analogWrite( pin, (int)((*currentLevel) / 100. * 255) );
                                              delay( FADE_DELAY );
                                            }
                                          }
                                          
                                          martinhjelmareM Offline
                                          martinhjelmareM Offline
                                          martinhjelmare
                                          Plugin Developer
                                          wrote on last edited by
                                          #31

                                          @drock1985

                                          As I wrote above, switches are not supported yet, in the default releases of home assistant. That support only exists in my personal branches at github.

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


                                          24

                                          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