Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ControlValue sensor, OptionsFlow and RestoreState to make better use of Ngenic Track with UtilitySensors #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

andersteern
Copy link

First off, thanks for creating this platform

This PR consists of 3 parts

Add NgenicControlTempSensor

The API exposes a CONTROL_VALUE sensor that indicates the adjustment made by the tune on the outdoor temperature.
This value is made available in a new temperature sensor sensor.ngenic_controller_control_value

Prepare Ngenic Track Energy Sensor for UtilityMeter

As explained in here the source sensor should/could implement RestoreEntity to store it's state between restarts.

To cater for that the NgenicEnergySensor now has it's state stored and updated on load

The other change to the NgenicEnergySensor is that the value of sensor.ngenic_sensor_energy now reads the total number of kWh's consumed since installation

Add options to replace the current/previous month sensors with utility meters

The Integration now has an OptionsFlow that will make all additions of meters optional.

image

The default setting will be to not add utility meters, and keep the current sensor.ngenic_sensor_monthly_energy and sensor.ngenic_sensor_last_month_energy untouched

* Add Option to create utility meters
* Add Options to keep current/last month sensors
* Add RestoreState Sensor
* Use RestoreState for NgenicEnergySensor
* Use Option to add Utility Meters
* Use Option to add current/previous month Sensors
@andersteern andersteern changed the title Add ControlValue OptionsFlow and RestoreState to make better use of Ngenic Trak with UtilitySensors Add ControlValue sensor, OptionsFlow and RestoreState to make better use of Ngenic Track with UtilitySensors Dec 30, 2020
@sfalkman
Copy link
Owner

This is great! I didn't even know about UtilityMeter :-)
I got a couple of questions though

  1. As I understand the UtilityMeter, it will keep an internal history of changes of the source entity (the total consumption since 2000). This may lead to a state where the UtilityMeter and our own Ngenic sensor that fetch this information from the Ngenic servers becomes out of sync. For example, if your homeassistant goes down but your Ngenic gateway is alive and continues reporting to the Ngenic servers. I don't see any issue with this, however, the options you've added (and this out-of-sync limitation) should be documented in the readme.

  2. When I configure the integration (Configuration -> Integrations -> Ngenic -> Options) the changes are not reflected without reloading the integration, is this expected? Also, when disabling the last two options (for monthly sensors) those existing sensors are not removed (they only become unavailable), but when disabling the UtilityMeter the entities are removed. Do we want the same behavior?

2.2 I've noticed a bug where we start receiving errors in the log when reloading the integration. This doesn't have anything to do with you changes, but if the workflow is to reload the integration after any changes it needs to be fixed first. I've reported this here: #23

  1. Do you know if it's possible to link the UtilityMeter sensor to the Ngenic integration? What I'd like is to see the UtilityMeters as entities connected to the Ngenic integration when going to Configuration -> Integrations.

@andersteern
Copy link
Author

1.

For example, the daily utility meter resets it's value to 0 at 00:00:00. This means that it is still possible to "catch" an update on the wrong day, since the source meter is updated every 10 minutes. But as long as we can accept that every kWh is registered pretty close to the correct day, the utility meters will give a pretty good estimate. Worst case would be if the energy meter is updated at 00:00:01, which would then register the entire poll period on the wrong day.
The same thing happens when you restart or take your HA offline for a while. The first update after a restart will register the entire change, but on the current meter cycles.

Perhaps, in another PR, I could try to reschedule the updates of the energy sensor to reduce the chance of having the energy register in the wrong cycle

2.

I am not sure how removed (or orphaned) sensors can be (forcefully) removed

2.2.

I noticed this as well, but didn't look into it. I will definitely follow #23 . Right now a HA restart is required after the options are updated 🤔

3.

Good catch. It should be possible to alter the utility meters when adding them. I will a look at this

A use case

I use the UtilityMeters together with custom:mini-graph-card that lets you set group_by and use aggregate_func: max to produce graphs like this one
image

@andersteern
Copy link
Author

Now UtilityMeter sensors will be added to the entity registry and show up under "Ngenic Tune"

Also, I added a comment in the README suggesting a HA restart if options are changed

@sfalkman
Copy link
Owner

sfalkman commented Jan 3, 2021

Can you please check this out? #24 (comment)

@sfalkman
Copy link
Owner

Please rebase your branch so you'll get the fixes for #23

@Hedda
Copy link
Contributor

Hedda commented Dec 17, 2021

@andersteern Any chance you can rebase this so it cab be merged?

@tedenda
Copy link

tedenda commented Apr 13, 2022

This looks very nice @andersteern 👍

Do you have the time to rebase and update this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants