MySensors Raspberry Pi Gateway with HA

Mysensors just developed a new gateway, directly built using RPi GPIO.

Could we use it in HA?
How would be the config?

i think that the serial way is just like the serial way we had before.
(i actually see no reel advantage there)

the MQTT way must be implemented i think. i dont know how fast that would be there.

I think the advantage is making a gateway without Arduino and nothing connected to RPi usb…
Actually I have a mysensors gateway connected to RPi usb (two devices)
This new gateway is supposed to turn the RPi into a mysensors gateway by it self…
Not using the serial gateway neither the MQTT, just using the radio connected to GPIO…

yeah but they mention on the mysensors page you can use 2 ways. 1 is with an arduino connected to the RPI.
and there i see no advantage.

the second (without arduino) is using MQTT to get the data to the controller.

Not sure about that… I had understood this is a new type of gateway (they created a new topic under gateways), where we could install it just using GPIO from RPi. Is that was about just connecting the Pi to a serial Gateway, was not necessary creating a new topic, once I already use it like this.

Then they explain how to connect to an existing serial gateway IF you can’t install directly on the GPIO and the second example is about BUILDING a MQTT gateway based on the radio connected on the GPIO.

People who uses Domoticz on RPi got mysensors working just connecting the radio on the Pi.

Have I insanely misunderstood that?

you need to connect a radio to your pi.
obviously.
and then you need to get the incoming data to the controller program in any way.
the general way they chose is through MQTT (which is just a software protocol)

so yeah, you connect a radio and then use the MQTT protocol to get it into HA.

it is also possible to write a py script which gets the data and translates it to some datafiles and then connect sensors and switches out of HA to that.

the way with the arduino is through pinconnection. i still use 1 off the USB ports.

1 Like

@oliverdog i don’t know if you’ve fixed it but it is already implemented.

You can just use it as a lan device. f.example

mysensors:
  gateways:
    - device: '127.0.0.1'
      persistence_file: 'path/mysensors3.json'
      tcp_port: 5003

Thanks, but that still needs MQTT built for the gateway?
I want to build a gateway without needing internet connection.

I am using it with a serial gateway (arduino connected to rpi USB port).

What I want is connect the radio directly to Rpi and build a gateway that works just like a serial one, without internet… is it possible?

Thanks

even for MQTT you dont need internet.
most people who use HA with MQTT have a MQTT server on the RPI.

i guess its possible to connect the reciever directly to the RPI and create a python loop that functions equal to a mysensorsgateway. ( i havent seen anyone do it, but i dont see why it shouldnt be possible)

the only advantage i see with that is that you dont need an arduino.

maybe that @martinhjelmare knows if someone already did that.

1 Like

When you connect the radio directly to the RPi, you decide in the mysensors raspberry gateway build process configure script what kind of gateway you want to use, serial, ethernet or mqtt. Then you set up mysensors component as normal in home assistant for the gateway type you selected.

Internet is not involved, it can be if you eg use mqtt and have the broker hosted online, but that’s beside the point. You don’t need Internet for mysensors.

2 Likes

i guess i havent read the page the right way in october :wink:

so stupid how i sometimes just close my eyes for obvious developments and read things in the context that i know.
guess thats why i needed to call you again, to realize i could have known the answer all along.

2 Likes

did you configure it properly to work with HA?
I’m on it now and have no idea how to do it.
this is what settings are possible:

pi@raspberrypi:~/MySensors $ ./configure --help
configure script for MySensors gateway.
Options:

Help:
    -h, --help                  print this message

SPI driver options:
    --spi-driver=[BCM|SPIDEV]
    --spi-spidev-device=<DEVICE>
                                Device path. [/dev/spidev0.0]

Building options:
    --soc=[BCM2835|BCM2836|AM33XX|A10|A13|A20|H3]
                                SoC type to be used. [configure autodetected]
    --cpu-flags=<CPUFLAGS>      CPU defining/optimizing flags to be used. [configure autodetected]
    --extra-cflags=<CFLAGS>     Extra C flags passed to C compilation. []
    --extra-cxxflags=<CXXFLAGS> Extra C++ flags passed to C++ compilation. []
    --extra-ldflags=<LDFLAGS>   Extra C flags passed to linking. []
    --c_compiler=<CC>           C compiler. [arm-linux-gnueabihf-gcc][gcc]
    --cxx_compiler=<CXX>        C++ compiler [arm-linux-gnueabihf-g++][g++]
    --build-dir=<DIR>           Compiler directory to store object files. [build]
    --bin-dir=<DIR>             Compiler directory to store binary files. [bin]
    --arduino-lib-dir=<DIR>     Arduino library directory.
    --no-clean                  Don't clean previous build artifacts.

Installation options:
    --prefix=<PREFIX>           Installation prefix path. [/usr/local]
    --gateway-dir=<DIR>         Gateway files installation directory. [PREFIX/bin]

MySensors options:
    --my-debug=[enable|disable] Enables or disables MySensors core debugging. [enable]
    --my-config-file=<FILE>     Config file path. [/etc/mysensors.dat]
    --my-gateway=[ethernet|serial|mqtt]
                                Gateway type, set to none to disable gateway feature. [ethernet]
    --my-node-id=<ID>           Disable gateway feature and run as a node with given id.
    --my-controller-url-address=<URL>
                                Controller or MQTT broker url.
    --my-controller-ip-address=<IP>
                                Controller or MQTT broker ip.
    --my-port=<PORT>            The port to keep open on gateway mode.
                                If gateway is set to mqtt, it sets the broker port.
    --my-serial-port=<PORT>     Serial port. [/dev/ttyACM0]
    --my-serial-baudrate=<BAUD> Serial baud rate. [115200]
    --my-serial-is-pty          Set the serial port to be a pseudo terminal. Use this if you want
                                to connect to a controller running on the same device.
    --my-serial-pty=<NAME>      Symlink name for the PTY device. [/dev/ttyMySensorsGateway]
    --my-serial-groupname=<GROUP>
                                Grant access to the specified system group for the serial device.
    --my-mqtt-client-id=<ID>    MQTT client id.
    --my-mqtt-publish-topic-prefix=<PREFIX>
                                MQTT publish topic prefix.
    --my-mqtt-subscribe-topic-prefix=<PREFIX>
                                MQTT subscribe topic prefix.
    --my-transport=[none|nrf24|rs485|rfm95]
                                Transport type, set to none to disable transport feature. [nrf24]
    --my-rf24-channel=<0-125>   RF channel for the sensor net, 0-125. [76]
    --my-rf24-pa-level=[RF24_PA_MAX|RF24_PA_LOW]
                                RF24 PA level. [RF24_PA_MAX]
    --my-rf24-ce-pin=<PIN>      Pin number to use for rf24 Chip-Enable.
    --my-rf24-cs-pin=<PIN>      Pin number to use for rf24 Chip-Select.
    --my-rf24-irq-pin=<PIN>     Pin number connected to nRF24L01 IRQ pin.
    --my-rf24-encryption-enabled
                                Enables RF24 encryption.
                                All nodes and gateway must have this enabled, and all must be
                                personalized with the same AES key
    --my-rx-message-buffer-size=<SIZE>
                                Buffer size for incoming messages when using rf24 interrupts. [20]
    --my-rs485-serial-port=<PORT>
                                RS485 serial port. You must provide a port.
    --my-rs485-baudrate=<BAUD>  RS485 baudrate. [9600]
    --my-rs485-de-pin=<PIN>     Pin number connected to RS485 driver enable pin.
    --my-rs485-max-msg-length=<LENGTH>
                                The maximum message length used for RS485.
    --my-leds-err-pin=<PIN>     Error LED pin.
    --my-leds-rx-pin=<PIN>      Receive LED pin.
    --my-leds-tx-pin=<PIN>      Transmit LED pin.
    --my-leds-blinking-inverse  Inverse the blinking feature.
    --my-signing=[none|software]
                                Message signing. [none]
    --my-signing-debug          Enable signing related debug.
    --my-signing-request-signatures
                                Enable signature request from nodes that in turn requested
                                gateway signature.
    --my-signing-request-gw-signatures-from-all
                                Require all nodes in the network to sign messages sent to the
                                gateway.

pi@raspberrypi:~/MySensors $

I were used

./configure --my-gateway=serial --my-serial-is-pty --my-serial-pty=/dev/ttyMySensorsGateway --my-serial-groupname=tty

and when I put make, I get an error:

pi@raspberrypi:~/MySensors $ make
g++ -MT build/examples_linux/mysgw.o -MMD -MP -DMY_RADIO_NRF24 -DMY_GATEWAY_SERIAL -DMY_DEBUG -DMY_LINUX_SERIAL_GROUPNAME=\"tty\" -DMY_LINUX_SERIAL_PTY=\"/dev/ttyMySensorsGateway\" -DMY_LINUX_IS_SERIAL_PTY  -Ofast -g -Wall -Wextra  -I. -I./core -I./drivers/Linux -c examples_linux/mysgw.cpp -o build/examples_linux/mysgw.o
In file included from examples_linux/mysgw.cpp:74:0:
./MySensors.h:254:2: error: #error No support for nRF24 radio on this platform
 #error No support for nRF24 radio on this platform
  ^
In file included from ./drivers/RF24/RF24.cpp:23:0,
                 from ./MySensors.h:290,
                 from examples_linux/mysgw.cpp:74:
./drivers/RF24/RF24.h:52:17: fatal error: SPI.h: No such file or directory
 #include <SPI.h>
                 ^
compilation terminated.
Makefile:114: recipe for target 'build/examples_linux/mysgw.o' failed
make: *** [build/examples_linux/mysgw.o] Error 1

Any ideas what I can do?

Have you connected the radio to the GPIOs correctly? Are you sure the serial group name is tty of the serial device of your GPIOs? On my RPi it’s dialout. You should be able to check this:

ls -l /dev/

Find your GPIO serial port and check group. My device is called /dev/ttyAMA0.

I’m using this for version 1.4 https://forum.mysensors.org/topic/2437/step-by-step-procedure-to-connect-the-nrf24l01-to-the-gpio-pins-and-use-the-raspberry-as-a-serial-gateway-mysensors-1-x and all wirings are remain same for new version(don’t have IRQ connected - but it is optional).
1.4 gw I want remove (I don’t know how - for now), my output for ls -l /dev/: http://ix.io/1RJP

I want version 2.0 for gateway because my soil moisture sensor is sending data in version 2.0.

ok, I uninstalled old version of gw 1.4 using in /home/pi/Raspberry/ $sudo make uninstall -worked well.

Next, I installed new wersion gw 2.X like in tutorial and all is working, but not as I want:

pi@raspberrypi:~/MySensors $ sudo ./bin/mysgw -d
mysgw: Starting gateway...
mysgw: Protocol version - 2.1.1
mysgw: MCO:BGN:INIT GW,CP=RNNG---,VER=2.1.1
mysgw: TSM:INIT
mysgw: TSF:WUR:MS=0
mysgw: !TSM:INIT:TSP FAIL
mysgw: TSM:FAIL:CNT=1
mysgw: TSM:FAIL:PDT
mysgw: TSM:FAIL:RE-INIT

Code I’m using in my node: http://pastebin.com/LCjF5Cm1
It is written for version 2.0 - is this the problem why I am not getting any messages to gateway? Where I can find older version of gateway or how update code for node? Or is another problem?

Looks like the transport (radio) on the gateway failed to initialize. See this page for explanation on debug output.
https://ci.mysensors.org/job/Verifiers/job/MySensorsArduinoLibPR/Doxygen_HTML/group__MyTransportgrp.html

This problem should have nothing to do with any node.

ok, on mysensors forum they provide same answer for me, just added missing wire in my buil (IRQ-pin15)
configure and compile, install as in instruction:

./configure --my-gateway=serial --my-serial-port=/dev/ttyAMA0 --my-serial-baudrate=115200 --my-transport=nrf24 --my-rf24-irq-pin=15

nothing changed :confused:

 pi@raspberrypi:~/MySensors $ sudo systemctl status mysgw.service
â—Ź mysgw.service - MySensors Gateway daemon
   Loaded: loaded (/etc/systemd/system/mysgw.service; enabled)
   Active: active (running) since Sat 2017-02-04 13:31:31 CET; 6s ago
 Main PID: 7338 (mysgw)
   CGroup: /system.slice/mysgw.service
           └─7338 /usr/local/bin/mysgw

Feb 04 13:31:31 raspberrypi systemd[1]: Started MySensors Gateway daemon.
Feb 04 13:31:31 raspberrypi mysgw[7338]: Starting gateway...
Feb 04 13:31:31 raspberrypi mysgw[7338]: Protocol version - 2.1.1
pi@raspberrypi:~/MySensors $ /usr/local/bin/mysgw -d
mysgw: Starting gateway...
mysgw: Protocol version - 2.1.1
mysgw: MCO:BGN:INIT GW,CP=RNNG--Q,VER=2.1.1
mysgw: TSM:INIT
mysgw: TSF:WUR:MS=0
mysgw: !TSM:INIT:TSP FAIL
mysgw: TSM:FAIL:CNT=1
mysgw: TSM:FAIL:PDT
mysgw: TSM:FAIL:RE-INIT
mysgw: TSM:INIT
mysgw: !TSM:INIT:TSP FAIL
mysgw: TSM:FAIL:CNT=2
mysgw: TSM:FAIL:PDT
mysgw: TSM:FAIL:RE-INIT
mysgw: TSM:INIT
mysgw: !TSM:INIT:TSP FAIL
mysgw: TSM:FAIL:CNT=3
mysgw: TSM:FAIL:PDT
mysgw: TSM:FAIL:RE-INIT
mysgw: TSM:INIT
mysgw: !TSM:INIT:TSP FAIL
mysgw: TSM:FAIL:CNT=4
mysgw: TSM:FAIL:PDT
^Cmysgw: Received SIGINT

!TSM:INIT:TSP FAIL means “Transport device initialization failed” - no idea what is wrong. Should I add capacitor to my RF module?
I don’t know what I can chech/change or how debug it to find out what is wrong.

Not sure if this was already fixed, but I’m also interested in direct-SPI attached MySensors gateways.

Has there been any solutions discovered?

It shouldn’t be a problem. I’ve replied to your other posted topic.

1 Like

Hi there.
Long time since I created this topic and now I am facing another issue…

I had a docker setup of home assistant in a Rpi with a GPIO Mysensors Gateway.
Docker demands a lot of work to update when you need to upgrade Python version, and it happens sometimes, so I decided use the HASS.IO

But… you already know and I need to try again once I did not find the definitive negative answer.

Can I use a GPIO Rpi Mysensors Gateway with HASS.IO?
Is there a solution for that? Or is someone thinking about that addon yet?
An inverted dock maybe, such as installing a complete OS inside HASS.io and get sudo and make install?

If not, either I give up my hardware setup that worded fine for 5 years or give up the HASS.IO.

Btw, I have 14 Mysensors nodes, I changed an old router with Mysensors antenna, leds and Rpi inside, seeming like a bought solution…so building an usb Gateway would break that beauty.