[userModule] Automated Inactivity Switch Off (Up 2016/10/19)

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
maros
Posts: 103
Joined: 05 Apr 2014 11:21

[userModule] Automated Inactivity Switch Off (Up 2016/10/19)

Post by maros »

This module turns off devices after a defined time of inactivity. Activity can be measured using multiple binary sensors/devices, like movement sensors, door sensors or switches. Also allows to specify a delay for auto off checks after the device was initially turned on.

Tested with Z-Way version v2.2.2
Bug/Issue tracker at https://github.com/maros/Zway-AutoOffInactive/issues
Documentation at https://github.com/maros/Zway-AutoOffIn ... /README.md
Download at https://github.com/maros/Zway-AutoOffInactive/releases

Installation can be done directly via git or via the the Zway App-Store. Install the BaseModule first.
Last edited by maros on 04 Feb 2017 15:26, edited 5 times in total.
Z-Way 2.2.4 on Raspi B | My Zway GitHub repos | Amazon Wishlist to support module development
masque
Posts: 30
Joined: 23 Dec 2015 01:06

Re: [userModule] Automated Inactivity Switch Off

Post by masque »

Hi maros,
I get the following error when I create an App with this module:

Code: Select all

2016-01-04 21:21:00.236] [I] [core] Notification: error (core): Cannot instantiate module: AutoOffInactive: TypeError: Cannot read property 'call' of undefined
[2016-01-04 21:21:00.247] [I] [core] TypeError: Cannot read property 'call' of undefined
    at new AutoOffInactive (automation/userModules/AutoOffInactive/index.js:14:27)
    at AutomationController.instantiateModule (automation/classes/AutomationController.js:287:24)
    at AutomationController.createInstance (automation/classes/AutomationController.js:504:14)
    at ZAutomationAPIWebRequest._.extend.createInstance (automation/ZAutomationAPIProvider.js:656:40)
    at ZAutomationAPIWebRequest.ZAutomationWebRequest.handleRequest (automation/WebserverRequestRouter.js:258:41)
    at automation/WebserverRequestRouter.js:32:35
    at WebServer.document_root (automation/Webserver.js:27:11)
BTW. There is a typo in the installation instruction on GitHub.
it refers to WindowControl instead of AutoOffInactive.

Code: Select all

git clone https://github.com/maros/Zway-WindowControl.git WindowControl --branch latest
regards
masque
maros
Posts: 103
Joined: 05 Apr 2014 11:21

Re: [userModule] Automated Inactivity Switch Off

Post by maros »

hi, the dependency declaration was missing in module.json. This was fixed on the master branch
Z-Way 2.2.4 on Raspi B | My Zway GitHub repos | Amazon Wishlist to support module development
masque
Posts: 30
Joined: 23 Dec 2015 01:06

Re: [userModule] Automated Inactivity Switch Off

Post by masque »

It's working now. thanks.
Would it make sense to include Multi level switches for sensor as well ?
A logical rule could be used to define if the Multilevel switch has been inactive or not.
An example for usage would be: Turn of the washing maschine and send a notification if the powerlevel of the washing maschine as been 3W for more then 10 minutes.
Or am I wrong and such scenarios are solved with existing modules already ?
regards
masque
maros
Posts: 103
Joined: 05 Apr 2014 11:21

Re: [userModule] Automated Inactivity Switch Off

Post by maros »

Hi, you can already use binary switches as input sensors. Unfortunately your use-case is not covered by this module, and I don't think that it is covered by any other module out of the box. However I believe that it could be solved by combining this module with a virtual binary sensor that is triggered whenever the power level of the washing machine is < 3W and untriggered if > 3W (triggering could be done via custom js code or my ConditionSwitch module)
Z-Way 2.2.4 on Raspi B | My Zway GitHub repos | Amazon Wishlist to support module development
masque
Posts: 30
Joined: 23 Dec 2015 01:06

Re: [userModule] Automated Inactivity Switch Off

Post by masque »

I did a test with the "if then" module allready. Unfortunately it's not enougth to trigger between <3W and >3W as the maschine is reaching that condition during normal work as well. Therefore I was looking for something that includes a timer. This would give the possibility to only switch off the maschine when the power level is held for a certain time.
I thought about using your Automated Incativity Switch Off module for this, but it does use binray switches as sensor only. I'm not really a developer, but I thought about giving it a try to localy "customize" your module and try to include multi level switches. The bad point on this is, that I would spend a lot of time to end in a dead track, as all the changes you apply to the "normal" module would not go into my customized one.
But I guess you do not plan to include multi level switches to your module. right ? ;-)
maros
Posts: 103
Joined: 05 Apr 2014 11:21

Re: [userModule] Automated Inactivity Switch Off

Post by maros »

Actually the Inactivity Switch does not have a timer on its own. It simply runs periodically and checks the level and last update time of all sensors. If the sensors are off and if the last update is longer ago than the configured timeout then the device is switched off. Adding multilevel switches/sensors would be kind of hard here - since the last change timestamp changes frequently (eg. if the power meter changes from 3.2 -> 3.1W)

maybe try this solution
1. Create a virtual binary switch
2. Use my ConditionSwitch module to turn off the virtual switch whenever power level of the controlled device is >3w (and turn it on if <3w)
3. Use the Auto Inactivity Off module with the binary switch as sensor input
Z-Way 2.2.4 on Raspi B | My Zway GitHub repos | Amazon Wishlist to support module development
masque
Posts: 30
Joined: 23 Dec 2015 01:06

Re: [userModule] Automated Inactivity Switch Off

Post by masque »

ok, that's a cool idea.
I will try this as soon as I've figured out why the Conditional Switch module gives me the following error when I create an app.

Code: Select all

[2016-01-06 23:23:07.673] [I] [core] Notification: error (core): Cannot instantiate module: ConditionSwitch: TypeError: undefined is not a function
[2016-01-06 23:23:07.698] [I] [core] TypeError: undefined is not a function
    at AutomationController.instantiateModule (automation/classes/AutomationController.js:287:24)
    at AutomationController.createInstance (automation/classes/AutomationController.js:504:14)
    at ZAutomationAPIWebRequest._.extend.createInstance (automation/ZAutomationAPIProvider.js:656:40)
    at ZAutomationAPIWebRequest.ZAutomationWebRequest.handleRequest (automation/WebserverRequestRouter.js:258:41)
    at automation/WebserverRequestRouter.js:32:35
    at WebServer.document_root (automation/Webserver.js:27:11)
As the error does not come from the module it has to be something else.
This time permissions are ok, so I will have to check what else could casue this.
masque
Posts: 30
Joined: 23 Dec 2015 01:06

Re: [userModule] Automated Inactivity Switch Off

Post by masque »

ok, we're getting closer. After restarting everything I now get the following error:

Code: Select all

[2016-01-06 23:39:09.775] [E] [core] Callback execution error: ReferenceError: dayNow is not defined
    at automation/userModules/ConditionSwitch/index.js:139:46
    at Function._.each._.forEach (automation/lib/underscore.js:146:17)
    at ConditionSwitch.checkCondition (automation/userModules/ConditionSwitch/index.js:123:11)
    at ConditionSwitch.initCallback (automation/userModules/ConditionSwitch/index.js:66:10)
shouldn't it be dayofweekNow instead of dayNow ?
masque
Posts: 30
Joined: 23 Dec 2015 01:06

Re: [userModule] Automated Inactivity Switch Off

Post by masque »

I've changed line 139 in index.js to dayofweekNow and got the ConditionSwitch Module working.
Additionally I've added the binary switch to the module.json of AutoOffInactive module as the Binary switches have not been shown in the drop down list.

Code: Select all

 "sensors" : {
            "fields" : {
               "item" : {
                  "datasource" : "namespaces",
                  "field" : "optionLabels",
                  "optionLabels" : "namespaces:devices_sensorBinary:deviceName,namespaces:devices_switchBinary:deviceName",
                  "type" : "select"
....

"sensors" : {
            "items" : {
               "datasource" : "namespaces",
               "enum" : "namespaces:devices_sensorBinary:deviceId,namespaces:devices_switchBinary:deviceId",
               "field" : "enum",
               "required" : true
after this I have been able to configure everything.
Unfortunately it is not working. :-(
The ConditionSwitch seems to be OK, but AutoOff is not triggering.
I guess it's not just to add the binary switches.
Post Reply