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. Development
  3. Getting values from outside my nodes

Getting values from outside my nodes

Scheduled Pinned Locked Moved Development
9 Posts 4 Posters 1.4k Views 5 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.
  • CrankyCoderC Offline
    CrankyCoderC Offline
    CrankyCoder
    wrote on last edited by
    #1

    I am adding more sensors and some of the values in my code I would like to be able to update dynamically. Like my smoothing counters, delays ect.

    I have seen there is a "request" function that I can use. I was wondering if anyone has any suggestions on how to utilize this with an mqtt gateway. I use openhab as my backend controller so if anyone has any suggestions or direction that would be helpful and prevent me from having to keep pulling my nodes and flashing them.

    Thanks!

    Home Automation Tinkerer
    www.CrankyCoder.net

    Controller: HomeAssistant in Kubernetes
    Gateway: MQTTClientGateway
    MySensors: 2.3

    1 Reply Last reply
    0
    • CrankyCoderC Offline
      CrankyCoderC Offline
      CrankyCoder
      wrote on last edited by
      #2

      Update: so I have taken one of my modules an added the following to the loop every 10 seconds.

      request(1, 24);
      

      I see messages hitting my mqtt broker
      0_1514586586276_8e663e5e-8b1e-4b1b-8ffd-3309b08f9c27-image.png

      The payload is blank. So I am trying to figure out how to get openhab to see the request (but the value isn't changing) and then be able to respond back with a value.

      Secondly, has anyone done this with openhab and been able to create a rule that can look for all NODES asking for a req?

      so maybe something like monitoring mygateway1-out/+/+/2/# or whatever watching for just requests?

      I am hoping there is a way to do this with openhab/mysensors directly, otherwise i may have to go to mqttwarn and monitor for requests and query openhab and respond. (not ideal)

      Home Automation Tinkerer
      www.CrankyCoder.net

      Controller: HomeAssistant in Kubernetes
      Gateway: MQTTClientGateway
      MySensors: 2.3

      berkseoB 1 Reply Last reply
      0
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by
        #3

        Look at the pulse energy meter sketch, it uses the request function to retrieve the last pulse count from controller

        1 Reply Last reply
        0
        • CrankyCoderC Offline
          CrankyCoderC Offline
          CrankyCoder
          wrote on last edited by
          #4

          that part I was able to figure out. Was hoping someone had some working examples on how to get the controller to monitor for those requests and answer back.

          I think I got it working, but not sure if it's the right way to do it or not. Will post details momentarily.

          Home Automation Tinkerer
          www.CrankyCoder.net

          Controller: HomeAssistant in Kubernetes
          Gateway: MQTTClientGateway
          MySensors: 2.3

          Boots33B 1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #5

            I think it should be taken care by the mysensors plug in without too much tinkering, but I haven't used Openhab

            1 Reply Last reply
            1
            • CrankyCoderC CrankyCoder

              that part I was able to figure out. Was hoping someone had some working examples on how to get the controller to monitor for those requests and answer back.

              I think I got it working, but not sure if it's the right way to do it or not. Will post details momentarily.

              Boots33B Offline
              Boots33B Offline
              Boots33
              Hero Member
              wrote on last edited by
              #6

              @crankycoder said in Getting values from outside my nodes:

              that part I was able to figure out. Was hoping someone had some working examples on how to get the controller to monitor for those requests and answer back.

              I think it is as @gohan has said, if the controller supports request it will be handled automatically and returned to the asking node.

              You have to have code in your void receive(const MyMessage &message) to do something with the returning request. In Domoticz I have found it can take several hundred milliseconds for the request to return so you may have to wait before you get a result.

              Nodes can also request data directly from other nodes but you need to handle the request and return manually in that case as the controller will not be involved.

              You may find the info in this post of some use.
              I have also used request in this project where you can see the delay needed before reading the return.

              CrankyCoderC 1 Reply Last reply
              3
              • Boots33B Boots33

                @crankycoder said in Getting values from outside my nodes:

                that part I was able to figure out. Was hoping someone had some working examples on how to get the controller to monitor for those requests and answer back.

                I think it is as @gohan has said, if the controller supports request it will be handled automatically and returned to the asking node.

                You have to have code in your void receive(const MyMessage &message) to do something with the returning request. In Domoticz I have found it can take several hundred milliseconds for the request to return so you may have to wait before you get a result.

                Nodes can also request data directly from other nodes but you need to handle the request and return manually in that case as the controller will not be involved.

                You may find the info in this post of some use.
                I have also used request in this project where you can see the delay needed before reading the return.

                CrankyCoderC Offline
                CrankyCoderC Offline
                CrankyCoder
                wrote on last edited by
                #7

                @boots33 checking out those references.

                Home Automation Tinkerer
                www.CrankyCoder.net

                Controller: HomeAssistant in Kubernetes
                Gateway: MQTTClientGateway
                MySensors: 2.3

                1 Reply Last reply
                0
                • CrankyCoderC Offline
                  CrankyCoderC Offline
                  CrankyCoder
                  wrote on last edited by
                  #8

                  So here is what I ended up doing. This may be long....

                  First off, I put this code in to my node.

                  if(currentMillis - previousMillisSettings >= 300000) 
                    {
                      previousMillisSettings = currentMillis;
                      request(2, 24);
                      wait(MESSAGEWAIT);
                      request(2, 25);
                      wait(MESSAGEWAIT);
                      
                    }
                  

                  So I am just requesting V_VAR1 and V_VAR2 for child sensor ID2.

                  Ok, so, so far so good. However, openhab doesn't do anything with that since I am using the mysensors MQTT gateway. So I loaded up MQTT spy and saw the requests for the info.

                  So now lets get openhab to monitor for that.

                  2 new items created in the openhab config.

                  String MasterBedRoomLightSleepTimeReq {mqtt="<[mqtt-brunkhome:mygateway1-out/200/2/2/0/24:state:default]"}
                  String MasterBedRoomLightNumReadingsReq {mqtt="<[mqtt-brunkhome:mygateway1-out/200/2/2/0/25:state:default]"}
                  

                  just 2 items watching for those requests.

                  Now 2 more items to be the configuration items.

                  Number MasterBedroomLightSleepTime  
                  Number MasterBedroomLightNumReadings
                  
                  

                  Then I created 2 rules (I know it's getting long).

                  rule "Request Sleep Time"
                  when
                          Item MasterBedRoomLightSleepTimeReq received update
                  then
                          logInfo("Bedroom","Bedroom Counter Requested")
                          publish("mqtt-brunkhome","mygateway1-in/200/2/1/0/24",(MasterBedroomLightSleepTime.state).toString())
                  
                  
                  
                  
                  rule "Request Num Readings"
                  when
                          Item MasterBedRoomLightNumReadingsReq received update
                  then
                          logInfo("Bedroom","Bedroom Light Sensor Reading Count")
                          publish("mqtt-brunkhome","mygateway1-in/200/2/1/0/25",(MasterBedroomLightNumReadings.state).toString()))
                  
                  

                  These 2 rules see's anytime there is something on those mqtt nodes, and responds back to the mqtt gateway with the info.

                  Then in my node, I put the following in my receive()

                  if (message.type==V_VAR1) {
                      DEBUG_PRINT("Sleep Time Sent Back");
                      SLEEPTIMEL = atoi(message.data);
                      DEBUG_PRINTLN(atoi(message.data));
                    }
                    else if (message.type == V_VAR2)
                      {
                      DEBUG_PRINT("Read Count Sent Back");
                      numReadings = atoi(message.data);
                      DEBUG_PRINTLN(atoi(message.data));
                    }
                  

                  And now my openhab is responding to config requests.

                  I then went back and updated the number items to also push config too. So the node can come get the config, but if you change it, it also pushes real time too.

                  Number MasterBedroomLightSleepTime  { mqtt=">[mqtt-brunkhome:mygateway1-in/200/2/1/0/24:command:*:default]" }
                  Number MasterBedroomLightNumReadings  { mqtt=">[mqtt-brunkhome:mygateway1-in/200/2/1/0/25:command:*:default]" }
                  

                  SOOO.... here is my question..... is this even the right way to do this? I mean with this method for EVERY variable I have to create an item to watch for the request, one to hold the value of said variable, and a rule?

                  Just wondering if anyone has done this with openhab or even something else that just uses the mqttgateway.

                  PS. i am going to cross post this on the openhab community as well.

                  Home Automation Tinkerer
                  www.CrankyCoder.net

                  Controller: HomeAssistant in Kubernetes
                  Gateway: MQTTClientGateway
                  MySensors: 2.3

                  1 Reply Last reply
                  0
                  • CrankyCoderC CrankyCoder

                    Update: so I have taken one of my modules an added the following to the loop every 10 seconds.

                    request(1, 24);
                    

                    I see messages hitting my mqtt broker
                    0_1514586586276_8e663e5e-8b1e-4b1b-8ffd-3309b08f9c27-image.png

                    The payload is blank. So I am trying to figure out how to get openhab to see the request (but the value isn't changing) and then be able to respond back with a value.

                    Secondly, has anyone done this with openhab and been able to create a rule that can look for all NODES asking for a req?

                    so maybe something like monitoring mygateway1-out/+/+/2/# or whatever watching for just requests?

                    I am hoping there is a way to do this with openhab/mysensors directly, otherwise i may have to go to mqttwarn and monitor for requests and query openhab and respond. (not ideal)

                    berkseoB Offline
                    berkseoB Offline
                    berkseo
                    wrote on last edited by berkseo
                    #9

                    @crankycoder I do not know if I understood you correctly ...

                    void request (uint8_t childSensorId, uint8_t variableType, uint8_t destination);

                    Suppose you have a node with ID 100 sends request (1, 24); (= request (1, 24, 0))

                    This means that the node with ID 100 requests the information with the last value for sensor 1 with the type VAR1 that is on the controller for the node with ID 100. (not at sensor 1 on the gateway (ID 0)

                    Ie at such request of a node with ID 100 requests value as though at itself (that last value which is on the controller).

                    request (1, 24);
                    request (1, 24, 0);

                    It is the same.

                    ps/// I understood :) .. on OpenHub there is no implementation of the MySensors module

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


                    15

                    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