Report in Imperial Units



  • Hello,

    I am exploring the use of MySensors, and fairly convinced it will suit my needs. I have been looking at things over the past week and found much of what I currently have need for. That said:

    If I understand things correctly, the use of Imperial or Metric units is controlled either by a Controller, or the Gateway. I use HomeSeer as my primary controller but the plugin is not being developed farther for the newer HomeSeer V4 interface. As a result I decided to use an MQTT gateway instead of the V3 plugin and the serial gateway. So in essence I do not believe I have a dedicated Controller. So how do I configure my Gateway to use Imperial as opposed to Metric units?

    I MAY look at picking up the HomeSeer plugin but it would be my first foray into plugin development for HomeSeer so this is highly doubtful.

    Kindest Regrds,
    Karl S



  • @Karl-S Welcome!

    If I understand you correctly, you only care about imperial units. In this case, simply send imperial units from your sensor nodes to HomeSeer or any other controller of your choice. There is no configuration required.

    That being said, a controller can "tell" the MySensors network if it uses metric or imperial units, which the gateway will store as a isMetric flag in a ControllerConfig object. Any MySensors node can retrieve the controller config from the gateway, so that you can implement the logic to convert and send measurements in either one or the other unit.

    This is helpful if you share sketches publicly in which you want to provide both metric and imperial measurements out of the box, so that nobody who uses your sketch needs to change a thing. But if you write a sketch for yourself, simply ignore the configuration and send imperial measurements.



  • @BearWithBeard said in Report in Imperial Units:

    @Karl-S Welcome!

    If I understand you correctly, you only care about imperial units. In this case, simply send imperial units from your sensor nodes to HomeSeer or any other controller of your choice. There is no configuration required.

    Thank you for the reply. This is what I would like, so how do I "Simply" send these? Do I need to do conversions via code or can I somehow set the sensor node to do this automatically? When I read the above it sounds as if I can set, configure, the sensor node to read in imperial units. The only reference I have found so far is pre MySensors V2 and it would have me supply the math to do conversions. Not a huge deal, but if the capability exists, I missed it in any documentation (entirely feasible) and I would rather use such.

    Karl



  • Well, MySensors doesn't care at all about units when you send a message. It gives you the freedom to measure and send whatever you like. Be it temperature readings as °F, °C, °K or even °Re.

    Note that MySensors is just the communication framework. Everything else needs to be handled by you, the sketch developer. You handle the sensor interaction and - if necessary - do the required unit conversions manually or with the help of a suitable Arduino library. Just as you would in other non-MySensors projects.

    Let's say you want to get the temperature from a BME280 sensor and use SparkFun's library to interact with it. If you only care about imperial units, call the readTempF() function they provide to store the temperature in Fahrenheit in a variable and send it to HomeSeer.

    BME280 bme;
    MyMessage msg(CHILD_ID, V_TEMP);
    //...
    void loop()
    {
    	// ... every 5 minutes ...
    	
    	float temp = bme.readTempF();
    	msg.send(temp);
    	
    	// ... return to sleep ...
    }
    

    No controller configuration required, and that's totally fine. The vast majority of MySensors users would do it this way.

    While MySensors doesn't care about units, as I mentioned above, it still enables you to check which system of units the connected controller wishes to receive using the ControllerConfig object. With this, you could write sketches which conditionally send different values for those users who use a controller with imperial units than those, who configured it for metric units.

    BME280 bme;
    MyMessage msg(CHILD_ID, V_TEMP);
    bool metric = true;
    float temp;
    
    void setup()  
    { 
    	metric = getControllerConfig().isMetric;
    }
    
    
    void loop()
    {
    	// ... every 5 minutes ...
    	
    	if (metric)
    	{
    		temp = bme.readTempC();
    	} else 
    	{
    		temp = bme.readTempF();
    	}
    	msg.send(temp);
    	
    	// ... return to sleep ...
    }
    

    If I would use a sketch with a condition like this, it would send the temperature in °C to my Home Assistant controller, since it uses the metric system. For you, on the other hand, it would send °F to your imperial HomeSeer setup.

    I feel like I gave you the same answer as above, just differently worded. 😅
    Still, I hope this makes it a little bit clearer for you.



  • @BearWithBeard said in Report in Imperial Units:

    ...
    I feel like I gave you the same answer as above, just differently worded. 😅
    Still, I hope this makes it a little bit clearer for you.

    Thank you very much for this. What you did in this one is flat out state that MySensors is unit agnostic and does no conversion, etc. The existence of getControllerConfig().isMetric made me think there was more than a setting which said "This network is in a imperial/metric location." Probably because I am not used to coding or examples for both via a setting, but typically see "comment out ___ and uncomment ___ for ___ units." I now understand that this was my error and do agree that the setting is a better solution than I am familiar with. So while you may feel you stated the same, what was missing for me was a that the sensor library was used to control reporting units and not MySensors. Makes sense to me as I was wondering how mixed units might be handled.

    Again, thank you very much for explaining this.

    Kindest Regards,
    Karl S



  • Thanks for solving this problem.


Log in to reply
 

Suggested Topics

  • 5
  • 3
  • 10
  • 931
  • 1
  • 65
  • 10

210
Online

10.3k
Users

10.7k
Topics

109.8k
Posts