FlyingDiver / Indigo-Occupatum

Location and Occupancy plugin for the Indigo Home Automation System
MIT License
2 stars 4 forks source link

Actions for dynamically updating device settings #14

Closed rbdubz3 closed 2 years ago

rbdubz3 commented 2 years ago

I use the occupatum devices - both Activity and Occupancy - for energy saving and turning off lights/etc when no-one is in a room. At certain times of the day, i'd like this logic to be more aggressive.. For example - I have some motion activated lights in a couple of rooms and I'd like to turn them off after just 60 seconds of inactivity in the middle of the night, but maybe more relaxed during the day at 5 minutes or so.

I have some related logic - fwiw - that is based around my local energy company and Time-of-use (TOU) billing.. Basically I am charged a higher rate of electricity during peak hours of the day when the broader region is using more grid power.. Hence I also adapt the energy saving logic in my house around these hours of the day.

So the feature request is to support actions for the devices to be able to update the various devices settings - 'Time Window for activations', 'Activations required', 'Delay On', 'Delay Off', etc. This will allow triggers and schedules to dynamically update these periodically throughout the day

FlyingDiver commented 2 years ago

Wouldn't it be easier to make multiple Occupatum devices for the different time periods or schedules, then use action groups to enable/disable the devices?

FlyingDiver commented 2 years ago

Hmm. Maybe not. I'll have to think about this.

rbdubz3 commented 2 years ago

Wouldn't it be easier to make multiple Occupatum devices for the different time periods or schedules, then use action groups to enable/disable the devices?

I can see if it's possible to support this with a combination of multiple Occupatum devices and other logic.. My older home-grown implementation had similar settings exposed as Indigo Variables - and i'd update the variable values throughout the day via custom scripts based on my energy company TOU times/etc

FlyingDiver commented 2 years ago

Yeah, but then you've got to split the actions to separate action groups called from triggers for multiple devices. Not ideal either. I'll mock up some actions and you can see how that works.

FlyingDiver commented 2 years ago

https://github.com/FlyingDiver/Indigo-Occupatum/releases/tag/2022.1.0

rbdubz3 commented 2 years ago

Wow - thanks for the quick turnaround Joe! i'll test it out this week

rbdubz3 commented 2 years ago

Hey Joe - testing this out with some python scripting in triggers. Hate to ask cuz it's probably something simple on my end. For some reason I get an exception when attempting 'updateOccupancyZone' action - however, similar code works fine for the 'updateActivityZone' action.. See below:

## Convenience log function
def log(msg):
    indigo.server.log(msg, type="ZZZ Test Script Exec Plugin Action")

pluginId = "com.flyingdiver.indigoplugin.occupatum"
thePlugin= indigo.server.getPlugin(pluginId)

theDevice = indigo.devices['Media Room Activity Zone']
log(u'Device name {}, states "{}".'.format(theDevice.name,theDevice.states))

thePlugin.executeAction("updateActivityZone", deviceId=theDevice.id, props={'activityWindow':1800,'activityCount':5})

theDevice = indigo.devices['Media Room Occupancy Zone']
log(u'Device name {}, states "{}".'.format(theDevice.name,theDevice.states))

thePlugin.executeAction("updateOccupancyZone", deviceId=theDevice.id, props={'onDelayValue':0, 'offDelayValue':2700})

When I test this script i get the following output:

   ZZZ Test Script Exec Plugin Action Device name Media Room Activity Zone, states "States : (dict)
     onOffState : on (on/off bool)
     onOffState.ui : on (string)".
   ZZZ Test Script Exec Plugin Action Device name Media Room Occupancy Zone, states "States : (dict)
     delay_timer : 0 (real)
     force_off_timer : 0 (integer)
     onOffState : on (on/off bool)
     onOffState.ui : on (string)".
   Script Error                    embedded script error:
   Script Error                    unable to convert python exception
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 17, at top level
RuntimeError: unable to convert python exception

Any help appreciated

FlyingDiver commented 2 years ago

You need a forceOffValue as well, even though you're not using it in the current config. Doesn't matter what the value is.