gtdiehl / iotawatt_ha

IoTaWatt for Home Assistant
Apache License 2.0
16 stars 16 forks source link

Sensors based on output and returning frequency or power factor return 0 #19

Closed darek-margas closed 3 years ago

darek-margas commented 3 years ago

As per subject - these sensors are auto-added and then value is 0 while iowatt reports output correctly.

Cheers,

gtdiehl commented 3 years ago

This appears to be an issue with the IoTaWatt Query and how the iotawattpy API is querying it.

Currently the API makes some assumptions as does not use a unit modifier, and lets the IoTaWatt query use the defaults. It appears this default is not working in some cases.

The API retrieves a list of inputs and outputs using two URLs http://iotawatt/query?show=series http://iotawatt/status?inputs=yes&outputs=yes

Both URLs do return the units for the input/output

For example, the URL being used now from the API side would be something like: http://iotawatt/query?select=[pftest,Spa]&begin=d&end=s&group=all

For the above pftest output the output is configured with a unit of pf, though the default IoTaWatt is using in the query is watts which in turn the return value is 0 for that sensor.

Notice in the select array the name of the input/output is given. If the URL is changed to: http://iotawatt/query?select=[pftest.pf,Spa.watt]&begin=d&end=s&group=all

We would get the correct value for the pftest output sensor. In the first two URLs above we do get the unit value from the IoTawatt. If we save the unit value (which I think we do already), and append the unit type to each of the sensors in the select array this should fix the issue.

This would need to be fixed in the iotawattpy library side through