Implementing a new controller


  • Contest Winner

    Hello Folks,

    I'm writing some code to make my Home Automation Suite project (https://sourceforge.net/projects/my-house/) acting as a controller. I went through old posts here on this topic, the source code of the engine, the serial protocol and API documentation as well as I've reviewed the code of other open source controllers to have an idea of what it really takes.
    I'm almost done but there are still a few things not completely clear to me. If I go through the list of functionalities that must be supported by a controller (https://www.mysensors.org/controller), I'm unsure about the following:

    • Heartbeat support: assuming this is not referring to smart sleep support which is a different item, as far as I have understood the controller is not supposed to reply to heartbeat requests (also because the controller does not have a node id). If a request is for a sensor in the network, the gateway would push it towards the radio network without even reaching the controller, if the destination is 0, the gateway itself would respond. What does this really imply?
    • Ack support: similar to the above, looks like the ack is handled by the gateway when a message comes from the radio network and it is requesting an ack.
    • Request: I've seen controllers handling requests on behalf of other sensors but apparently if e.g. sensor 1 requests something to sensor 2, the gateway would route the message to sensor 2 directly so there is no need for the controller to replay back to 1, right?

    All clear instead for the others: node id generation, OTA support and smart sleep.

    Thanks in advance!
    Dave


  • Admin

    Welcome @user2684, nice project you got going!

    1. I_HEARTBEAT_RESPONSE could be seen as a "I'm alive" message from a node. The I_HEARTBEAT_REQUEST can be used by the controller to ping (woken) sensors. The will respond with a I_HEARTBEAT_RESPONSE.
    2. Yes, ack is handled by the gateway. Controller is not involved in this communication.
    3. Yes, the controller will not even see the message if it is routed to some other sensor.


  • Wow i like the look of this!.
    Especially the boiler sheduling and the ability to add decent graphs.
    I have been using domoticz for over a year but it is far too restricted when it comes to the gui.
    Shame i can not give it a go on my linux desktop,but never mind i have another raspi3 coming in the next few days so i will give it a whirl.



  • Well i switched my sd card on my working pi and installed as per instructions.
    The script installed everything and the service.
    But i can not access the web interface??


  • Contest Winner

    @hek thanks for the prompt answer! Very clear, I should be close to a first working draft then. I'll update about my progress here once ready for some testing.


  • Contest Winner

    @rmtucker thanks for your feedback first of all! I'd be more than happy to look into your issue, most likely some dependency is broken despite the installation script is supposed to deploy everything needed. The log file in the "logs/myHouse.log" directory should tell the full story. Or you can run the program directly with "sudo python myHouse.py" to review the output.
    If you don't mind following up this conversation on https://sourceforge.net/p/my-house/tickets/157/ would be great, otherwise we can easily go off topic here 🙂
    Thanks again


  • Hardware Contributor

    Very interesting project !
    I have a rpi3 too and I'll give it a try asap, like rmtucker I am a bit frustrated with the Domoticz UI...


  • Contest Winner

    Hi, I've just committed a working alpha version of myHouse acting as a controller. If anyone is interested to give it a try or to review the implementation, feel free to download the snapshot from https://sourceforge.net/p/my-house/code/ci/b8d057329438c7c434f7de6b8e76dc9bdee13ca6/tree/. Of course this is a development version, it does not necessarily work great. Feel free to report any issue here or on https://sourceforge.net/p/my-house/tickets/153/.

    The implementation is pretty simple, the gateway has to be configured in the "plugins" section (it will be part of the default configuration in the next release) and once a sensor is configured in one of the modules of myHouse, anytime a message is received from the given node_id,child_id,command,type tuple, the payload is saved as a new measure. It does support both ethernet, serial and mqtt gateways but does not support multiple gateways to run together for now. Node id generation is supported as well as smart sleep (messages are queued and delivered once the sensor is back online).

    The sensors have to be configured before starting receiving data (this is the logic of myHouse so I couldn't change it to allow "discovering" of new sensors).

    Full documentation of the stable version of myHouse can be found here https://sourceforge.net/p/my-house/wiki/. FYI the first time you look at the configuration, it is not really user friendly but eventually results pretty flexible. If already running it, I'd recommend creating a separate instance and using a different database to avoid interfering with the stable version.

    The global configuration looks like the following:

    	"mysensors": {
    		"enabled": true,
    		"gateway_type": "ethernet",
    		"gateways": {
    			"serial": {
    				"port": "/dev/ttyAMA0",
    				"baud": 57600
    			},
    			"ethernet": {
    				"hostname": "localhost",
    				"port": 5003
    			},
    			"mqtt": {
    				"hostname": "localhost",
    				"port": 1883,
    				"subscribe_topic_prefix": "mysensors-out",
    				"publish_topic_prefix": "mysensors-in"
    			}
    		}
    	}
    

    A temperature sensor using the plugin would look like the following:

            {
    		  "module_id": "test",
              "group_id": "temperature",
              "sensor_id": "test",
    		  "enabled": true,
              "display_name": {
    			"en": "Temperature"
    			},
              "plugin": {
                "plugin_name": "mysensors",
    			"node_id": 254,
                "child_id": 1,
    			"command": "SET",
    			"type": "V_TEMP"
              },
              "format": "temperature"
            }
    

    Thanks



  • @user2684 said in Implementing a new controller:

    Node id generation is supported as well as smart sleep (messages are queued and delivered once the sensor is back online).

    Just wondering how that would work without auto discovery?
    So the controller assigns a node id but how would you find out what node id had been assigned so you could enter it like above?


  • Contest Winner

    The controller can assign a sensor the node id and since every message the sensor sends back to the controller is logged, you can get the id from the logs and then configure you sensor in myHouse. Not ideal I know but would allow a pretty fast start and this is a one time only task.


Log in to reply
 

Suggested Topics

  • 2
  • 4
  • 48
  • 10
  • 2
  • 6

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts