Created At

Nov 05, 2020

Last Update

Jan 04, 2021

Platforms

HC 2

Views

2048

Download

221

BATTERY MONITOR

Displays the power levels of all battery operated devices.

  • The UI of the VD displays the 9 devices with the lowest power levels, sorted low to high.
  • The debugging window of the VD displays all battery operated devices.
  • Dead devices are clearly marked in the UI.

Optionally, every day at 20:00, notifications are sent. Both push notifications and email notifications are supported. Notifications can be sent to the phones and email addresses of users defined in the Fibaro system. Individual notifications are sent for each battery that is below a specified (configurable) level.

Technical details

The VD main loop runs frequently (specified by VD_ui_refresh_interval) to ensure the ui is kept up to date. Default is 5 minutes.

A check for notifications is done once a day, at 20:00. The accuracy of that moment is determined by VD_ui_refresh_interval. The VD only checks if it is 20:00 every 5 minutes.

The VD uses global variable BATMON_CONFIG to store its configuration. It contains:

  • last time the notifications check took place
  • next time for notifications check.

If the global variable does not exist, it is created automatically. Let the VD create the variable, do not do it manually.

Virtual Device configurable parameters

(in the code of the main loop)

Variable default value description
VD_ui_refresh_interval 5*60*1000 interval between runs of the main loop [msec]
VD_ui_num_battery_lines 9 Number of lines in the VD UI that can display a battery status. Only change this when you have added or removed a 'Batteryxx' line in the UI.
VD_user_ids_for_email {2} IDs of users that should receive email notifications. Leave empty to disable email notifications.
VD_phone_ids_for_push_messages {6} IDs of  phones for push notifications. Leave empty to disable push notifications.
VD_push_notification_threshold 15 battery level under which a push notification is generated [%]
VD_notification_override_interval 0 if ~=0, this interval [sec] will override the usual interval of 1 day
VD_extended_debugging false extended debugging for testing purposes. The stuff you do not need to see when all goes well.

 Credits

  • debug window logging mostly from "Battery Check Scene" by mysmarthome-cba-pl, available from Fibaro marketplace
  • some code fragments from "Advanced Battery Check (ABC) VD standalone 1.0" by   Sankotronic, available from Fibaro.com forum, virtual devices. Very extensive VD. Too much for what I need, but check it out if you need extensive battery management.

Version history

V1, Dec-2020 : Added email notifications. Minor code cleanup.
V0, Oct-2020 : Initial version

Copyright

None. Use, adapt, distribute to your liking.
I appreciate a comment to indicate what you like and dislike about the VD.

1 Comment,  Want to add comment please login
4c6b4571cf862dccfc23c0508ace2995

For anyone facing the same problem as me that certain devices has battery level 255% when depleted I made the following change in the code: if (device_is_dead) then battery_level = 0; else battery_level = tonumber(fibaro:getValue(device_id, "batteryLevel")); -- For devices returning battery level 255 at critical low, replace with 1 if (battery_level == 255) then battery_level = 1; end end

Load more comments
© 2024. Nice-Polska Sp. z o.o.Privacy policyTerms & ConditionsFeedback