gruijter / com.plugwise.smile

Athom Homey app to integrate Plugwise Smile P1 energy meter
GNU General Public License v3.0
0 stars 4 forks source link

Gas measurement is incorrect when < 1 m3 per hour #10

Closed eelco2k closed 5 years ago

eelco2k commented 5 years ago

Hi,

I found an issue when gas interval amount in one hour is less than 1m3 the difference calculation is incorrect. it rounds with Math.round() but then less than 1 (for example. 0.323 m3 per hour) it will always return 0.

See line: https://github.com/gruijter/com.plugwise.smile/blob/e0ede165567b904a9a5ebaa03e905e43853d63f8/drivers/smilep1/driver.js#L113

would be very nice for the gas bill when i stay every hour under 1 m3 🤣

eelco2k commented 5 years ago

instead of Math.round you can use .toPrecision(2)

gruijter commented 5 years ago

Thx. toPrecission is not the same as rounding. Also it returns a string in stead of number. But I will check if I can increase rounding to 1 decimal place.

eelco2k commented 5 years ago

sorry saw the same problem yes.... and .toFixed(2) ??

parseFloat(((( newmeter - lastmeter) / passedHours)).toFixed(2));

gruijter commented 5 years ago

That also returns a string and is not flawless in rounding. For some weird reason there is no easy 100% working round function in node. But I'll fix it no worries

eelco2k commented 5 years ago

lastmeter = 2205.34; newmeter = 2205.83; passedHours = 1; dif = parseFloat(((( newmeter - lastmeter) / passedHours)).toFixed(2)); console.log(typeof(dif));

returns in node here: number...

eelco2k commented 5 years ago

not sure why the passedHours is in the formula btw...?

eelco2k commented 5 years ago

okay for me also a nice read:

https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary#12830454

learned something new 👍 i already was searching for the precision in the math.round like in PHP but there isn't 👎

gruijter commented 5 years ago

Passedhours is needed to calculate flow (m3/h) from meter (m3).

Yes, I found the same read a year ago when I wanted to round off numbers but got weird results. Node is sometimes funny.

gruijter commented 5 years ago

mmh, I cannot reproduce the problem yet. Concernnig the rounding: I use the exact same code for my youless app, and that works fine. What smile version are you using? And is the gas total meter correct?

eelco2k commented 5 years ago

I’m using the latest version 3.3.6 Plugwise firmware. And yes the total current gas amount displays correct in homey.

Op 24 aug. 2019 om 11:15 heeft gruijter notifications@github.com het volgende geschreven:

mmh, I cannot reproduce the problem yet. Concernnig the rounding: I use the exact same code for my youless app, and that works fine. What smile version are you using? And is the gas total meter correct?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

eelco2k commented 5 years ago

Although I’m using the insight data to retrieve the gas amount for further processing into another app. The insight also gives me weird very small numbers. And in the app the activity (only changes once in +-24 hours) not sure if the insights are correct then.

In conclusion Insights doesn’t give me the same day period values as the plugwise app gives me.

Op 24 aug. 2019 om 11:15 heeft gruijter notifications@github.com het volgende geschreven:

mmh, I cannot reproduce the problem yet. Concernnig the rounding: I use the exact same code for my youless app, and that works fine. What smile version are you using? And is the gas total meter correct?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

eelco2k commented 5 years ago

Schermafbeelding 2019-08-24 om 11 29 25

As you can see there are spikes in the range of 0 and 0.0015 which is not the same as in the plugwise app. in those periods. Even the time of occurance of the spikes do not match. so homey is making numbers up ;-)

When i hover over a spike, it also just say: 0 so could also be a client side rounding issue

gruijter commented 5 years ago

Found a combination of problems. Testing now if that solves it :) (making my son take a shower, then wait an hour :( )

gruijter commented 5 years ago

v3.0.4 is available on Github and pending approval for Athom appstore.

gruijter commented 5 years ago

v3.0.4 2019.08.24 SmileP1 package v 1.2.0. Added autodiscover during pairing. Gas usage fix.

eelco2k commented 5 years ago

Hi @gruijter,

unfortunately Insights data is still not correct in v3.0.4

I've added the last 6 hours of today. And here my plugwise app data of the same day.

11:00 0,08 m3 12:00 0,06 m3 15:00 0,05 m3 16:00 0,16 m3 17:00 0,14 m3

Elektra & Gasmeter — Gas (Last 6 Hours).csv.zip Schermafbeelding 2019-08-28 om 18 58 11

gruijter commented 5 years ago

MMh, Can you please post the .csv of both the Gas AND Gas Meter over the same period? The Gas is calculated from the Gas meter reading (it is not coming directly from the Smile)

I would need the highest resolution (one minute interval, so last 1 hour or last 6 hours) that show at least once a faulty Gas reading. Last 24 hours might also be good enough, but then Homey reduces the sample resolution to 5 minute interval.

eelco2k commented 5 years ago

GAS meter csv

2019-08-29 09:38:00 2211.31 2019-08-29 09:39:00 2211.31 2019-08-29 09:40:00 2211.3683333333333 2019-08-29 09:41:00 2211.45 2019-08-29 09:42:00 2211.45

GAS interval csv

2019-08-29 09:38:00 0 2019-08-29 09:39:00 0 2019-08-29 09:40:00 0.08749999999999998 2019-08-29 09:41:00 0.21000000000000002 2019-08-29 09:42:00 0.21000000000000002 2019-08-29 09:43:00 0.21000000000000002 2019-08-29 09:44:00 0.21000000000000002 2019-08-29 09:45:00 0.1225 2019-08-29 09:46:00 0 2019-08-29 09:47:00 0

Plugwise App 2019-08-29 @ 9:00 (whole hour) 0,15 m3

I'm not having that much data for today, yet.

btw i have a DSMR 5 gas/electra smart meter. so gas is reported every 5 min. instead of 1 hour.

gruijter commented 5 years ago

I think something goes wrong still with the timestamp. My meter only reports once an hour, so I cannot test your situation where the gas is reported every 5 minutes.

Between 9 and 10 you used around 0.14 m3 (which is rounded the same as what Plugwise reports) But you use it between 9.40 and 9.45 (assuming/guessing those timestamps are used by your smartmeter). So the flow per hour should be reported as 12 * 0.14 = 1,7 m3/hr for a duration of 5 minutes, but in my app it shows 0.21 m3/hr.

Could you try to go to the webinterface of your smile, and after logging in go to: smileIPaddress/core/direct_objects

and post the resulting XML here? (via right-click save as file)

eelco2k commented 5 years ago
<domain_objects>
<script/>
<gateway id="f55dd73c93d14fb89a79c4a3335ee02c">
<created_date>2019-06-07T17:55:14.454+02:00</created_date>
<modified_date>2019-08-29T00:01:20.686+02:00</modified_date>
<deleted_date/>
<name/>
<description/>
<enabled>true</enabled>
<firmware_locked>false</firmware_locked>
<prevent_default_update>false</prevent_default_update>
<last_reset_date>2019-06-07T17:55:14.454+02:00</last_reset_date>
<last_boot_date>2019-07-27T16:20:16.358+02:00</last_boot_date>
<vendor_name>Plugwise</vendor_name>
<vendor_model>smile</vendor_model>
<hardware_version>AME Smile 2.0 board</hardware_version>
<firmware_version>3.3.6</firmware_version>
<mac_address>C4930007F1DC</mac_address>
<short_id>pjbdnhpx</short_id>
<send_data>true</send_data>
<anonymous>true</anonymous>
<lan_ip/>
<wifi_ip>10.0.0.41</wifi_ip>
<hostname>smile07f1dc</hostname>
<time>2019-08-29T00:01:26+02:00</time>
<timezone>Europe/Amsterdam</timezone>
<ssh_relay>disabled</ssh_relay>
<project id="5a2ed018667740a4bda0ba7ee1ea1e40">
<name>-- Webshop orders</name>
<description>
Gateways ordered through webshop and other non-specific deliveries
</description>
<is_default>false</is_default>
<visible_in_production>false</visible_in_production>
<deleted_date/>
<modified_date>2019-06-07T17:55:21.659+02:00</modified_date>
<created_date>2014-11-19T17:47:52+01:00</created_date>
</project>
<gateway_environment id="cafcdf17b15f4ea7ad6c797c3ba4cfeb">
<savings_result_value/>
<longitude/>
<thermostat_model/>
<city/>
<country/>
<electricity_consumption_tariff_structure>double</electricity_consumption_tariff_structure>
<electricity_production_peak_tariff>0.238</electricity_production_peak_tariff>
<central_heating_model/>
<household_children>0</household_children>
<thermostat_brand/>
<electricity_production_off_peak_tariff>0.224</electricity_production_off_peak_tariff>
<central_heating_installation_date/>
<postal_code/>
<electricity_consumption_off_peak_tariff>0.224</electricity_consumption_off_peak_tariff>
<latitude/>
<gas_consumption_tariff>0.72</gas_consumption_tariff>
<modified_date>2019-06-07T18:10:27.034+02:00</modified_date>
<electricity_production_tariff_structure>double</electricity_production_tariff_structure>
<housing_construction_period>unknown</housing_construction_period>
<electricity_production_single_tariff/>
<electricity_consumption_peak_tariff>0.238</electricity_consumption_peak_tariff>
<electricity_consumption_single_tariff/>
<central_heating_brand/>
<housing_type>apartment</housing_type>
<currency>EUR</currency>
<savings_result_unit/>
<household_adults>0</household_adults>
<central_heating_year_of_manufacture/>
<deleted_date/>
<modified_date>2019-06-07T18:10:27.034+02:00</modified_date>
<created_date>2019-08-27T18:10:40+02:00</created_date>
</gateway_environment>
<features>
<remote_control id="ce66fae6453f477092c47004f7a8ea85">
<activation_date>2019-06-07T17:48:35+02:00</activation_date>
<validity_period/>
<valid_to/>
<valid_from/>
<grace_period/>
<deleted_date/>
<modified_date>2019-06-07T17:55:21.699+02:00</modified_date>
<created_date>2019-06-07T17:48:35+02:00</created_date>
</remote_control>
</features>
</gateway>
</domain_objects>
eelco2k commented 5 years ago

and the direct objects:

<direct_objects>
<script/>
<appliance id="b1630bcb302743f4a84f861d4f62cda7">
<name>Gateway</name>
<description>
Container for variables logged about the Gateway in general.
</description>
<type>gateway</type>
<created_date>2019-06-07T17:55:15.779+02:00</created_date>
<modified_date>2019-08-29T15:30:09.030+02:00</modified_date>
<deleted_date/>
<groups/>
<logs>
<point_log id="149b3bef21dc4be890fcec3fbf4e713a">
<updated_date>2019-07-27T16:16:19.821+02:00</updated_date>
<type>lan_ip_address</type>
<unit/>
<last_consecutive_log_date>2019-07-27T16:16:18+02:00</last_consecutive_log_date>
<period start_date="2019-07-27T16:16:19.821+02:00" end_date="2019-07-27T16:16:19.821+02:00">
<measurement log_date="2019-07-27T16:16:19.821+02:00">10.0.0.57</measurement>
</period>
<network_address id="878dd07eb6664c829a40bce972c8908c"/>
</point_log>
<point_log id="339af1354ff34be1a7be3b845001c992">
<updated_date>2019-08-29T15:30:08.993+02:00</updated_date>
<type>wlan_state</type>
<unit/>
<last_consecutive_log_date>2019-08-27T19:55:48.645+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:30:08.993+02:00" end_date="2019-08-29T15:30:08.993+02:00">
<measurement log_date="2019-08-29T15:30:08.993+02:00">up</measurement>
</period>
<network_state id="841a667b4dab485e923bba345b0c2af5"/>
</point_log>
<point_log id="4ffc2431298f42be9398604c4901d1c2">
<updated_date>2019-08-29T15:30:08.993+02:00</updated_date>
<type>wlan_ip_address</type>
<unit/>
<last_consecutive_log_date>2019-08-18T00:26:52+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:30:08.993+02:00" end_date="2019-08-29T15:30:08.993+02:00">
<measurement log_date="2019-08-29T15:30:08.993+02:00">10.0.0.41</measurement>
</period>
<network_address id="d0b66d2bc56a47059f2760d484866b0a"/>
</point_log>
<point_log id="60c76c6c1b0b4cbe83ad58a466adea98">
<updated_date>2019-08-29T15:30:08.992+02:00</updated_date>
<type>signal_strength</type>
<unit>dBm</unit>
<last_consecutive_log_date>2019-08-29T15:30:08.992+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:30:08.992+02:00" end_date="2019-08-29T15:30:08.992+02:00">
<measurement log_date="2019-08-29T15:30:08.992+02:00">-66.00</measurement>
</period>
<signal_strength id="c4e6266415df41af95929cc3443bb9d0"/>
</point_log>
<point_log id="894194018f434e75ac45fbb7eef8ae8f">
<updated_date>2019-08-29T15:25:33.228+02:00</updated_date>
<type>lan_state</type>
<unit/>
<last_consecutive_log_date>2019-07-27T16:20:56.321+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:25:33.228+02:00" end_date="2019-08-29T15:25:33.228+02:00">
<measurement log_date="2019-08-29T15:25:33.228+02:00">down</measurement>
</period>
<network_state id="4692ef6a2bf841329a7ef125612922bd"/>
</point_log>
<point_log id="913674932bf84bd8980e5e8d10f885b8">
<updated_date>2019-08-29T15:30:08.992+02:00</updated_date>
<type>link_quality</type>
<unit/>
<last_consecutive_log_date>2019-08-29T15:30:08.992+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:30:08.992+02:00" end_date="2019-08-29T15:30:08.992+02:00">
<measurement log_date="2019-08-29T15:30:08.992+02:00">44</measurement>
</period>
<link_quality id="c38a7c822c264b949b65c407e6a03ea5"/>
</point_log>
</logs>
<actuator_functionalities/>
</appliance>
<location id="1ee6b5bf5bca4224b47b2318ffe3d20c">
<name>Home</name>
<description>A building with a smart meter.</description>
<type>building</type>
<created_date>2019-06-07T17:55:26.128+02:00</created_date>
<modified_date>2019-08-29T15:31:11.937+02:00</modified_date>
<deleted_date/>
<preset>home</preset>
<clients/>
<appliances/>
<logs>
<cumulative_log id="097555ef53a742c6aef0bbcea04028de">
<updated_date>2019-08-29T15:30:00+02:00</updated_date>
<type>electricity_consumed</type>
<unit>Wh</unit>
<last_consecutive_log_date>2019-08-29T15:30:00+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:30:00+02:00" end_date="2019-08-29T15:30:00+02:00">
<measurement log_date="2019-08-29T15:30:00+02:00" tariff="nl_peak">3408160.00</measurement>
<measurement log_date="2019-08-29T15:30:00+02:00" tariff="nl_offpeak">6127988.00</measurement>
</period>
<electricity_cumulative_meter id="01d1d6d285b54664a3787bedc679c85e"/>
</cumulative_log>
<point_log id="204e90a6a98b4a1bb60c039b30057572">
<updated_date>2019-08-29T15:30:39+02:00</updated_date>
<type>electricity_produced</type>
<unit>W</unit>
<last_consecutive_log_date>2019-08-29T15:30:39+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:30:39+02:00" end_date="2019-08-29T15:30:39+02:00">
<measurement log_date="2019-08-29T15:30:39+02:00" tariff="nl_peak">865.00</measurement>
<measurement log_date="2019-08-29T15:30:39+02:00" tariff="nl_offpeak">0.00</measurement>
</period>
<electricity_point_meter id="d457a361ebf5460d8caeca8ed0dfb103"/>
</point_log>
<point_log id="350c1bc88018492cac0a8e0a3a71cc47">
<updated_date>2019-08-29T15:30:39+02:00</updated_date>
<type>electricity_consumed</type>
<unit>W</unit>
<last_consecutive_log_date>2019-08-29T15:00:07+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:30:39+02:00" end_date="2019-08-29T15:30:39+02:00">
<measurement log_date="2019-08-29T15:30:39+02:00" tariff="nl_peak">0.00</measurement>
<measurement log_date="2019-08-29T15:30:39+02:00" tariff="nl_offpeak">0.00</measurement>
</period>
<electricity_point_meter id="d457a361ebf5460d8caeca8ed0dfb103"/>
</point_log>
<interval_log id="3b0df03bd7bd42f5a68815a93836fccc">
<updated_date>2019-08-29T14:00:00+02:00</updated_date>
<type>gas_consumed</type>
<unit>m3</unit>
<last_consecutive_log_date>2019-08-29T14:00:00+02:00</last_consecutive_log_date>
<interval>PT1H</interval>
<period start_date="2019-08-29T14:00:00+02:00" end_date="2019-08-29T14:00:00+02:00" interval="PT1H">
<measurement log_date="2019-08-29T14:00:00+02:00">0.00</measurement>
</period>
<gas_interval_meter id="3db0a2e182784f3fa4d01ad0851f61b0"/>
</interval_log>
<cumulative_log id="3b75507808214a408780a802c798c6f3">
<updated_date>2019-08-29T15:00:00+02:00</updated_date>
<type>gas_consumed</type>
<unit>m3</unit>
<last_consecutive_log_date>2019-08-29T15:00:00+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:00:00+02:00" end_date="2019-08-29T15:00:00+02:00">
<measurement log_date="2019-08-29T15:00:00+02:00">2211.45</measurement>
</period>
<gas_cumulative_meter id="682b9124b4644c108b206e7f77fd60d8"/>
</cumulative_log>
<interval_log id="5cd5fbb36aab4879ba07acb6f8eb55e0">
<updated_date>2019-08-29T15:15:00+02:00</updated_date>
<type>electricity_produced</type>
<unit>Wh</unit>
<last_consecutive_log_date>2019-08-29T15:15:00+02:00</last_consecutive_log_date>
<interval>PT15M</interval>
<period start_date="2019-08-29T10:00:00+02:00" end_date="2019-08-29T15:15:00+02:00" interval="PT15M">
<measurement log_date="2019-08-29T10:00:00+02:00" tariff="nl_offpeak">0.00</measurement>
<measurement log_date="2019-08-29T15:15:00+02:00" tariff="nl_peak">48.00</measurement>
</period>
<electricity_interval_meter id="490f5a8fccfe42c5bb37f440dfbfb580"/>
</interval_log>
<cumulative_log id="82b1929c340e4def90e1b47b8b477074">
<updated_date>2019-08-29T15:30:00+02:00</updated_date>
<type>electricity_produced</type>
<unit>Wh</unit>
<last_consecutive_log_date>2019-08-29T15:30:00+02:00</last_consecutive_log_date>
<period start_date="2019-08-29T15:30:00+02:00" end_date="2019-08-29T15:30:00+02:00">
<measurement log_date="2019-08-29T15:30:00+02:00" tariff="nl_peak">1056457.00</measurement>
<measurement log_date="2019-08-29T15:30:00+02:00" tariff="nl_offpeak">482300.00</measurement>
</period>
<electricity_cumulative_meter id="01d1d6d285b54664a3787bedc679c85e"/>
</cumulative_log>
<interval_log id="91348077d14842769466181c01819b9a">
<updated_date>2019-08-29T15:15:00+02:00</updated_date>
<type>electricity_consumed</type>
<unit>Wh</unit>
<last_consecutive_log_date>2019-08-29T15:15:00+02:00</last_consecutive_log_date>
<interval>PT15M</interval>
<period start_date="2019-08-29T15:15:00+02:00" end_date="2019-08-29T15:15:00+02:00" interval="PT15M">
<measurement log_date="2019-08-29T15:15:00+02:00" tariff="nl_peak">0.00</measurement>
<measurement log_date="2019-08-29T15:15:00+02:00" tariff="nl_offpeak">0.00</measurement>
</period>
<electricity_interval_meter id="490f5a8fccfe42c5bb37f440dfbfb580"/>
</interval_log>
</logs>
<actuator_functionalities/>
</location>
</direct_objects>
eelco2k commented 5 years ago

the xml says also PT1H for gas interval

gruijter commented 5 years ago

The test I am running right now shows that the Homey app is registering the gas flow correct. Please be aware that gas flow (Homey Insights) is not the same as gas usage in an hour (Plugwise app). This only happens to be the same value when the meter reports per hour. In your case, where the meter reports every 5 minutes, the flow will be represented per 5 minutes, leading to numbers up to 12 * higher then what you see in Plugwise.