How to get non mysensor node (mqtt/ethernet) info to a my sensor node.



  • Hello.
    I was thinking of makeing a mimic panel sort of thing for my home security.
    I have smome PIR sensors and motion detecting cameras that post MQTT messages over ethernet to my controller(openhabian).
    I could make my mimic panel with an esp8266 and subscribe to thes messages ( know how to do this)...
    Or I could make a mysensors node, make some automation in my controller to publish the multiple sensors to mySensorsGW-in (don't really know how to do this)..

    Is there a way the mysensors MQTT gateway (it's an arduino with ethernet) can directly subscribe to the relevant messages and send the information i need to my mimic panel node.

    Would love to hear some thoughts on how to do any of these options or any other options I have.
    Gavin.



  • Welcome @gav!

    The MySensors MQTT gateway subscribes to any topic matching this pattern: mysensors-sub-topic/+/+/+/+/+. The wildcards are (in order) node ID, child sensor ID, command, ack and type (see here for details on the protocol API). Based on that you (or your controller using automations) could publish to any topic with that scheme and the gateway will pick it up. It then constructs a MyMessage object and forwards it to the destination node (the node with the mimic panel, in your case).

    For example mysensors-in/10/0/1/0/2 with a payload of 1 will cause the gateway to build a message that is directed to node ID 10 and tells it that there is a new value for its child ID 0, which we would like to set to 1 / true (the payload) and that the message is of type 2 (V_STATUS).

    I'm not familiar with OpenHAB, but I assume it provides a way to send custom messages to MySensors. If not, you can always fallback to using "raw" MQTT as shown above.

    In any case, make sure that you listen for the incoming message in receive() on the destination node. There is no automation in place for handling incoming messages. You have to make sense of it.

    bool isActive;
    
    void receive(const MyMessage &message) {
    	if (message.getSensor() == 0 && message.getType() == V_STATUS) {
    		isActive = message.getBool();
    	}
    }
    
    void loop() {
    	if (isActive) {
    		// Do something
    	}
    }
    

    Keep the receive() function as short as possible. Check the incoming message and assign variables or set flags here, but do all the time consuming logic inside the loop() to prevent locking up the node, causing recursive loops and such.

    Note that the node cannot be put into sleep when it is expected to listen for incoming messages.

    Hope this gives you an idea on how to handle such tasks using MySensors.



  • @BearWithBeard
    Thanks. That sounds like what I was thinking. Makes it clearer though.


Log in to reply
 

Suggested Topics

  • 8
  • 10
  • 1
  • 20
  • 3
  • 2
  • 1
  • 5

82
Online

10.3k
Users

10.7k
Topics

109.6k
Posts