Git Product home page Git Product logo

habpanel-widget-lastupdate-indicator's Introduction

Last update indicator widget for HABPanel (OpenHAB)

By making a donation, no matter how small, you are saying thanks and drawing a smile on my face because I will know, somebody thought my project was useful and worth paying for ๐Ÿคฉ. Donate

Description

Displays the time passed in hours when an item last received an update, it slowly goes to red when time increases. Usefull when using battery operated Zwave/Zigbee devices, those could die/drop of the network without you noticing. You cannot set the indicator directory to the item, you need to create a monitor rule for each device you wish to monitor. The rule updates a datetime item reflecting the last updated time of the monitored item.

Screenshot

Download

Prerequisites

  • You need to create a _lastUpdate item of type datetime for each device/item you want to monitor.
  • For each, create a rule which updates the _lastUpdate item to the last date it receved an update.

Example 1

This is an example for an battery operated Zwave smoke detector, but it shows the base princaple.

zwave.items

DateTime Zwave_Rookmelder_Gang_LastUpdate           "Laatst gezien [%1$ta %1$tR]"           <clock> (gZwave)

zwave.rules

rule "Rookmelder gang"
when
	Item Zwave_Rookmelder_Gang changed or 
	Item Zwave_Rookmelder_Gang_Battery changed or 
	Thing "zwave:device:a5062334:node2" received update
then
	Zwave_Rookmelder_Gang_LastUpdate.postUpdate(new DateTimeType())
end

Example 2

With this example, suggested by microneer, you can combine all devices in just one rule. Create a DateTime item per device with the trailing _LUD suffix.

// This Rule triggers when any Item in the gRecordLastUpdate Group is updated, and
// updates a virtual DateTime item with the same name as the Item but with _LUD as 
// a suffix, setting it to the current date and time.
rule "Record Last Update"
when
	Member of gRecordLastUpdate received update
then
	// Post an update to the item with the same name and _LUD suffix
 	sendCommand( triggeringItem.name+"_LUD", now.toString)
//	logInfo('lastUpdate', triggerItem.name)
end

Installation

  • Create a folder within '/conf/html/' folder, name it 'lastupdate-indicator'.
  • Place the 'lastupdate-indicator.controller.js' file in the '/conf/html/lastupdate-indicator/' folder.
  • Import the downloaded Last update indicator.widget.json widget to your HABpanel.
  • Add the widget to a dashboard, open the settings.
    • Select the _lastUpdate item.
    • Set the desired name which will be displayed in the widget.
    • Enjoy en drop me a like here on the Openhab cummunity forum.

The complete structure would look like this:

  • /conf/html
    • /lastupdate-indicator
      • lastupdate-indicator.controller.js

Help

If you need any help, use this topic on the Openhab community forum.

For issues and feature requests, please use the Issues module on Github.

habpanel-widget-lastupdate-indicator's People

Contributors

basvanh avatar williwacker avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

habpanel-widget-lastupdate-indicator's Issues

Easier Rule to set the last update Items

Perhaps you might want to suggest users set up a rule like the following, which means ONE rule for all monitored Things, not multiple Rules.

// This Rule triggers when any Item in the gRecordLastUpdate Group is updated, and
// updates a virtual DateTime item with the same name as the Item but with _LUD as 
// a suffix, setting it to the current date and time.
rule "Record Last Update"
when
	Member of gRecordLastUpdate received update
then
	// post an update to the item with the same name and _LUD suffix
 	sendCommand( triggeringItem.name+"_LUD", now.toString)
//	logInfo('lastUpdate',triggerItem.name)
end

Indicator wrong when server and browser timezone are different

I was just recently in Canada and was checking my OpenHub panels and found the lastupdate indicators out of time by 5-6h. This happens while the javascript library uses the browser timezone and the server the home zone. To prevent this it makes sense only working with UTC timestamps in the JS script.
I have changed the code to make it work:
`
function getLastupdate() {

try {
	var state = $scope.itemState($scope.config.lastupdate_item);						
	var now = new Date();

// var tzo = now.getTimezoneOffset()
// if (tzo != 0){
// now = new Date(now.getTime() - tzo60000);
// }
var last = new Date(state.slice(0, state.lastIndexOf("+")) + "Z"); //Crappy safari doesnt like timezone format
var state_tzo = last.getTimezoneOffset() //get state timezone
var timeDiff = Math.abs(last.getTime() + state_tzo
60000 - now.getTime());
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.