Changing the property output format

I have defined a home-made webthing with Temperature, BarometricPressure and Humidity Properties.

How do I make sure the text output format in the Gateway is congruent with those values? I would expect a setting within the webthing Property definition, but that does not seem to be the case as far as I could see.

Pressure shows hPa with 3 decimal places, when in general an integer would suffice.
Similarly relative humidity also shows with 3 decimal places, when in general an integer would suffice.
Conversely the temperature only shows units, when a decimal might be welcome.

My sensor shows way too many decimals for all, but I would expect to define the visual presentation, not change the numbers transmitted for presentation to doctor the presentation.

So how do I format sensor data in the Gateway?

You can control the number of decimal points in two ways:

  1. Set the type to integer: this will force it to show no decimal places.
  2. Set the multipleOf field in your property description. For instance, if you set "multipleOf": 0.1, it will only show a single decimal place.

I had partial success with your second method:

    self.add_property(
        Property(
            self,
            'temperature',
            Value(self.readings["temperature"]),
            metadata={
                 '@type':       'TemperatureProperty',
                 'title':       'Temperature',
                 'type':        'number',
                 'readOnly':    True,
                 'description': 'Temperature measured in °C',
                 'multipleOf':  0.1,
                 'unit':        '°C',
            }
        )
    )

    self.add_property(
        Property(
            self,
            'relative_humidity',
            Value(self.readings["relative_humidity"]),
            metadata={
                 '@type':       'HumidityProperty',
                 'title':       'Relative Humidity',
                 'type':        'number',
                 'readOnly':    True,
                 'description': 'Relative humidity in %',
                 'multipleOf':  1,
                 'unit':        '%RH',
                 'minimum':     0,
                 'maximum':     100,
            }
        )
    )

    self.add_property(
        Property(
            self,
            'pressure',
            Value(self.readings["pressure"]),
            metadata={
                 '@type':       'BarometricPressureProperty',
                 'title':       'Pressure',
                 'type':        'number',
                 'readOnly':    True,
                 'description': 'Air pressure in hecto-Pascals',
                 'multipleOf':  1,
                 'unit':        'hPa',
            }
        )
    )

I had to remove the webthing from the gateway and add it again for changes to take effect.

I think it would be great to have an optional “format” metadata descriptor.

Instead of using multipleOf: 0.1, just use type: 'integer', and make sure you’re setting it to an integer value.