-
Notifications
You must be signed in to change notification settings - Fork 466
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
Eve Energy: Improve the performance when the device is off #1087
Eve Energy: Improve the performance when the device is off #1087
Conversation
Timac
commented
Nov 24, 2023
- Don't the power reports of the device if the device is off
- In the timer, we now check if the device is off using device:get_latest_state()
- Set the power to 0 before the read is skipped so that the power is correctly displayed and not using a stale value
- Don't the power reports of the device if the device is off - In the timer, we now check if the device is off using device:get_latest_state() - Set the power to 0 before the read is skipped so that the power is correctly displayed and not using a stale value
Minimum allowed coverage is Generated by 🐒 cobertura-action against 3cc0a14 |
Channel deleted. |
- Add unit test to test the on attribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to satisfy the ST energy requirement, we still need to report the power consumption every 15 minutes (even when the device is off). I think this could be accomplished by moving the powerConsumptionReport
to it's own timer that runs every 15 minutes. This way it is not tied to the 1-minute timer (that could be stopped when the device is off with these changes) and the powerConsumptionReport will continue to report regardless of whether the device is on or off.
This would essentially mean moving the second half of the updateEnergyMeter
function (the part that only runs every 15 minutes) to his own function that is called every 15 minutes. This way it is decoupled from the 1-minute poll. What are your thoughts on this?
@@ -109,6 +109,12 @@ local function create_poll_schedule(device) | |||
-- The powerConsumption report needs to be updated at least every 15 minutes in order to be included in SmartThings Energy | |||
-- Eve Energy generally report changes every 10 or 17 minutes | |||
local timer = device.thread:call_on_schedule(TIMER_REPEAT, function() | |||
-- We want to prevent to read the power reports of the device if the device is off | |||
local is_off = device:get_latest_state("main", capabilities.switch.ID, capabilities.switch.switch.NAME) == "off" | |||
if is_off then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, we will only ever be turning off the polling is the device is off during device_init
, which is the only place create_poll_schedule
is called. However, we want to be able to remove the polling anytime the device is off. I would suggest moving this logic to the on/off handlers and then removing the poll timer when the device is off (see device_removed
for example) and then starting the timer again if the device is switched on and a timer is not already running (i.e. poll_timer == nil
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment, the timer will indeed always run but the requestData()
function won’t be called when the device is off.
We can change the behavior as suggested:
- stop the timer when the device is off and restart it when the device is switched on
- use a distinct timer to report the power consumption every 15 minutes
- Create the 1-minute timer when the device is switched on (if the timer doesn't exist yet) - Delete the 1-minute timer when the device is turned off - The totle consumption is saved in the variable LATEST_TOTAL_CONSUMPTION_WH - There is now a 15-minutes timer to send the powerConsumptionReport report to satisfy the ST energy requirement
Add one unit test