Expected reply from Controller if requesting a variable that does not exist?



  • I recently built a Pulse Powermeter Sensor and after wiring it up I realized that to start reporting data, it wants the pulse count from the controller. This creates a bit of a chicken/egg situation, as before the sensor has reported its first pulse count, there's no pulse count to report 🙂

    So, is there a documented default value the controller should report whenever it gets a request for a variable that does not exist? Or should it simply not reply in this case?

    My controller, Home Assistant, returns nothing - but I think that's partly because the pymysensors library used underneath seems to lack support for returning values to the sensors.

    So how should this work from the controller's point of view?


  • Plugin Developer

    @Erik-Forsberg

    Regarding pymysensors, yes it doesn't support req message type yet. I'm working on that. Just needs some more testing before I can submit it.


  • Plugin Developer

    @Erik-Forsberg

    Regarding home assistant, I think you can solve this with an automation rule and a custom script that uses the home assistant API, python or REST, to set the state of the powermeter (pulse count) in home assistant.

    For example, you send a value of 0 from the power meter, as long as no other value is coming from the controller. When the controller detects the value 0 from the powermeter, it fires the script, that sets the new pulse count of the powermeter in home assistant. Then the powermeter requests the value from the controller and will get the updated pulse count. Make sure you do the request before doing the send from the powermeter sensor.


  • Plugin Developer

    @Erik-Forsberg

    Regarding what the controller should reply when a device requests a value for a variable that doesn't exist, I think it shouldn't reply anything. I think it's the device that should initiate communication and setup and communicate the variables it will handle to the controller. The device should not ask the controller for a variable value that doesn't exist. If it does, the controller should just disregard that.

    That's my view, but I'd be interested in hearing others.



  • @martinhjelmare

    I tend to agree with that. In the case of the Power Meter, it should instead detect that it has never before booted and adapt to that.

    I'm glad to hear you're working on req message type. I, ehm, did that too: https://github.com/theolind/pymysensors/pull/22 🙂

    Your implementation is probably better since this is my first visit to this codebase, so feel free to reject the pull.


  • Plugin Developer

    @Erik-Forsberg

    I think one should be a bit careful about making too many special rules for different cases, between device and controller. I think there should be set ways of communicating between the controller and device. There should also be ways for the user to make rules to create the automations, but this should not change the set ways for communication.

    In this case, when we need an initial value from the user, which should be automated somehow, I think the user should be able to make rules, and somehow be able to set an initial state, by controller API or other means. But I think that should be detached from the specific device - controller communication.

    You can have a look at my handle_req branch here:
    https://github.com/MartinHjelmare/pymysensors/tree/handle_req

    I would say your implementation looks fine, although I have some comments. We can continue at github.


Log in to reply
 

Suggested Topics

  • 4
  • 1
  • 9
  • 9
  • 2
  • 933

18
Online

11.2k
Users

11.1k
Topics

112.5k
Posts