Proper way to add a feature
I would like to calculate Vapour Pressure Deficit on each climate sensor reading (if enabled via config). It requires the temperature and the relative humidity in the air.
Then I would like to be able to use a state trigger with a threshold on the result.
This feature should be sensor independent and shouldn't be present in dht or t9602 extensions.
I'm not sure on where to start to implement that. Should I create an extension ?
I have had similar ideas of wanting to do some data alterations that are not necessarily a extension on its own. It could be written as one for sure but maybe we should explore the templating route now.
There are a few places where this would be quite useful. You could manipulate data dynamically in any configuration where we accept this.
A start would be to add a template config property to the base component and then we can leave it up to each extension to implement this as need.
Then for example in a dht extension we can have a check if a template exists and apply it when it does the update cycle. In the extensions/dht/sensor.py as an example could be updated like so:
if self.template:
self._state = self.template.apply(readings)
else:
self._state = readings
return readings
This is around lines 154-157. The template logic would change to fit but this should give an idea.
If you think this is something you could take on it would be a huge help to me and a big addition to the system. I think of other areas like triggers and places this could be useful as well to have some simple logic to pass in and help add even more customization options.
This is just an example but image this would provide the ability to add a config like this to our dht:
{
"interface": "dht",
"key": "climate_reading",
"pin": "D24",
"model": 11,
"classifier": "humidity"
"template": "{{ value * 1.8 + 32}}"
}
This theoretical template uses double brackets to notate a template and assumes a variable value will be provided. I am sure we can provide a range of some useful values like time etc.
Does this seem like a good solution to your proposal as well? I think it opens up a lot of options. Plus there are a range of options in that template page we could possibly use even.
Sorry for the late reply. I'm quite busy lately, I'm not sure I will have time any time soon to implement that.
I will read about templating if I can spare some time and come back to you.
Thanks for showing the way :)