JohnvandeVrugt / toonapilib4domoticz

A simple toonapilib based python plugin for domoticz
MIT License
7 stars 6 forks source link

District heat not supported #20

Open martin-g-it opened 5 years ago

martin-g-it commented 5 years ago

Hi John,

First of all big hooray for this API/plugin; ever since Eneco discontinued the older API interface the build-in 'Toon Thermostat' hardware didn't work anymore..

While configuring this toonapilib4domoticz plugin, I noticed the District heat usage is not supported by the toonapilib. After some checking I figured out what to do in order to fix this from the API perspective; see below code changes. Tested this with the testtoonapilib.py and works like a charm.

Now on the Domoticz side, I think we should add some new device (heat.py) in line with the power.py/ gas.py. While doing so, perhaps also an idea to include a device showing the cumulative daily usage costs (toon.power.daily_cost / toon.heat.daily_cost / toon.gas.daily_cost ).

Are you willing to add this to the Domoticz part? What device type / subtype should be used?

Cheers, Martin


toonapilib changes (note: the python folder may be named differently based upon version running): /usr/local/lib/python3.7/dist-packages/toonapilib/helpers.py line 84 added:

HeatUsage = namedtuple('HeatUsage',
                        Usage._fields + Low._fields)

/usr/local/lib/python3.7/dist-packages/toonapilib/toonapilib.py line 49 added: HeatUsage,

line 420 added:

    @property
    def heat(self):

""":return: A power object modeled as a named tuple"""
        heat = self._get_status_value('heatUsage')
        return HeatUsage(heat.get('avgDayValue'),
                         heat.get('avgValue'),
                         heat.get('dayCost'),
                         heat.get('dayUsage'),
                         heat.get('isSmart'),
                         heat.get('meterReading'),
                         heat.get('value'),
                         heat.get('meterReadingLow'),
                         heat.get('dayLowUsage'))
darkrain-nl commented 4 years ago

I have added the cost in my test environment for Power and Gas, trying to figure out which device is best to use for this. There is a known issue that there is no cost for Power when using a double meter, only the high cost come through.

The heat I cannot add (or test as I don't have that here), your code changes first need to make it into the ToonApiLib, can you perhaps make a PR for that to happen?

I will test the cost for a few more days and create a PR after that.

martin-g-it commented 4 years ago

My Toon subscription has ended since I have rooted the device a few months back... I did create a daily cost device (Custom Sensor) based on the JSON from the Toon; calculated the daily costs via scripting; local PowerCostToday = domoticz.utils.round(tonumber(PowerUsageToday) 2109 / 10000, 2) local HeatCostToday = domoticz.utils.round(tonumber(HeatUsageToday) 26675 / 1000, 2) (Power costs 21,09 cents per KWh and heat costs 26,67 EUR per GJ)

I have a new Toon since last week, so let me bring back ToonApiLib on test domoticz environment and see if I can get things to work..

Example response from the Toon API for Heat: "heatUsage": { "value": 0, "dayCost": 0.43, "avgValue": 6.1, "meterReading": 1881, "avgDayValue": 146.29, "dayUsage": 18, "isSmart": 0, "lastUpdatedFromDisplay": 1575962257902 },

darkrain-nl commented 4 years ago

What device did you use for the cost? I now use Text and that works fine showing the current cost, but it doesn't create any nice graphical statistics. So I also tried with a managed counter, but that didn't work either.

martin-g-it commented 4 years ago

A type General, subtype Custom Sensor with 'Aslabel' EUR. You do get the graph, which increases over the day, and therefor has an average value which doesn;t make much sense, but thats the only disadvantage..

image image

darkrain-nl commented 4 years ago

Nice, changed and now testing again...