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
    #10

    For debugging with serial monitor, just plug in both the gateway and the node to your computer, either through USB if your arduino supports that or through FTDI adapter. Then open two instances of the Arduino IDE and open one serial monitor per IDE. Make sure you set board and port correct first, in the two IDEs, one per arduino. Mysensors use baudrate 115200, so make sure that's selected in the serial monitors.

    For an explanation of the mysensors' serial api, see:
    http://www.mysensors.org/download/serial_api_15

    In the end of that page there are some examples of serial output.

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

      Yes, it was just the baud rate that had me thrown off I guess, since the default is always 9600 on Arduino. Anyway, the serial gateway seems to be functioning as expected printing 0;0;3;0;9;gateway started, id=0, parent=0, distance=0 0;0;3;0;14;Gateway startup complete.

      However when I load up the motion sensor sketch and open the monitor, it still shows nothing. I then tried a couple different sensors incl. a PIR sensor with the distance example and another with the ds18b20 temp sensor with the same result. Finally I loaded up the MockMySensors sketch and again the serial monitor was blank.
      I then loaded up the default DigitalSerialRead sketch from the Arduino IDE and the serial output printed as expected. Then lastly, I even tested the PhysicalPixel sketch with the standard NRF24 library and it transmitted as expected! So the issue is definitely with the MySensors library. But then I still couldnt even get it to work using Codebender and that should be using a completely different library file. SO I'm all out of ideas... In any case, there still could be an issue on the Controller end, but I have no way of knowing until I can fix the sender function.

      1 Reply Last reply
      0
      • 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
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          22

                                          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