Creating variable script to operate within control page

Posted on
Mon Mar 02, 2020 6:26 pm
Eagleye offline
Posts: 83
Joined: Jan 14, 2019

Creating variable script to operate within control page

I was wondering if it is possible to add indicator lights to control pages that turns on when certain trigger conditions are meet?
E.g. I have a "Plug-in Smart Switch 6" connected to a power outlet that monitors power usage to a submersible in-ground water tank pump. I know when the pump is operating, because the power usage increases.
I would like to add an indicator light to my control page that turns on when power usage reaches a certain level and then off when it drops below another level.

I though variables might work here, but I have limited knowledge in this area.

Posted on
Wed Apr 22, 2020 8:49 pm
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Creating variable script to operate within control page

Variable would probably be the easiest route....

Create a variable "WaterTankPump" <- or whatever you want to call it.

Turn it on and write down the power usage. For example use, let's say it's 40w when on and 0.something when off.

Create two triggers, Both will be trigger off of the smart switch.
WaterTankPumpOn / Trigger when current load becomes greater than 30 / Condition=always / Actions: Variable Action: Modify Variable, WaterTankPump Set to "on"
WaterTankPumpOff / Trigger when current load becomes less than 30 /Condition=always / Actions: Variable Action: Modify Variable, WaterTankPump Set to "off"

Now you should be able to have a bi-color icon on a control page that looks at that variable.

To be a little fancier, create two actions.... WaterTankPump-On and WaterTankPump-Off. The actions would each have one action, to turn the smart switch on or off.

Now, create a Virtual on/off Device called "WaterTankPump". For on, select the action "WaterTankPump-On". For off, select "WaterTankPump-Off" action then select "Supports status" and use your "WaterTankPump" variable.

You can now use either the variable or the virtual device as a color changing icon on a control page, but now it's also a separate device that you can use for other stuff.... like from Indigo Touch.

FYI, if you have multiple things attached to that smart switch, you can figure out the different power consumption rates and write triggers to populate multiple variables.... example:

I have one of those in my kids room connected to their TV, DVD and Radio. Each use a different amount of power. 0-5 = all variables are off. 6-10w radio is on. 20-30 TV is on. 30+ radio and TV are on. So, at least 2 triggers per thing attached to that power switch but that gives me an icon on my control page to let me know if they leave their radio or TV on or provides a notification if their TV turns on during certain No-TV times.

Anyway, have fun.

Bill
My Plugin: My People

Posted on
Thu Apr 23, 2020 2:32 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Creating variable script to operate within control page

I do this with more than one kind of setup, but I do each in pretty much the same way. I set up two triggers--for example with our sump pump.

  1. The first trigger fires when energy usage becomes greater than 400 watts (with no conditions). When the trigger fires, I set a variable 'sump_pump" equal to True (the trigger also does a couple other things that don't matter here).
  2. The second fires when energy usage becomes less than 400 watts and does the reverse--setting the variable "sump_pump" equal to False.
I don't link this to an on/off image though. Instead, I use the Matplotlib plugin to create a chart that shows usage (although an on/off graphic would be very straightforward). In this chart, runtime duration is also shown, although the scale pretty much makes that too hard to see (ignore the long humps--those are an aberration).

chart_energy_sump.png
chart_energy_sump.png (6.56 KiB) Viewed 2230 times


I'm also considering some additional python code to track the number of pump cycles per day but haven't gotten around to that yet.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Apr 23, 2020 5:00 pm
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Creating variable script to operate within control page

DaveL17 wrote:
I'm also considering some additional python code to track the number of pump cycles per day but haven't gotten around to that yet.


I couldn't figure out the code, so I used triggers and schedules. Not for a pump, I use it to track internet stability. Between urban sprawl and COVID, my internet is up/down like a yo-yo.
I use a running timer for network uptime and another running timer for network downtime. Those provide the total up and down times by today, yesterday, last week, last month, this week, this month, this year (and a few other data points I don't use).

I wanted a pulse counter to track # of down times, not just duration totals. So, whenever my network goes down, DowntimeTodayVariable +1. DowntimeThisWeek +1, DowntimeThisMonth +1, and DowntimeThisYear +1

The next part is schedules.
Nightly at midnight. Set DowntimeYesterday to DowntimeToday. Set DowntimeToday to 0.
Weekly at midnight. Set DowntimeLastWeek to DowntimeThisWeek. Set DowtimeThisWeek to 0.
Monthly on the 1st. Set DowntimeLastMonth to DowntimeThisMonth. Set DowntimeThisMonth to 0.
Jan1. Set DowntimeLastYear to DowntimeLastMonth. Set DowntimeThisYear to 0.

Iv'e only been doing this for about 1-1/2 months and yes, my internet has been down for over 17 hours and 136 times during that period. Like I said, a total yo-yo.

Now, before you do what I did.... https://forums.indigodomo.com/viewtopic.php?f=333&t=23842 howartp is working on a Pulse Counting plugin.
Attachments
Network Yo-Yo.jpeg
Network Yo-Yo.jpeg (113.87 KiB) Viewed 2218 times

Bill
My Plugin: My People

Posted on
Fri Jun 26, 2020 11:42 pm
Eagleye offline
Posts: 83
Joined: Jan 14, 2019

Re: Creating variable script to operate within control page

Guys,

I know its been a while & I'm only just checking back in, but I would just like to thank you for the replies against this post. The instructions not only worked like treat, but it also allowed me to better under understand how variables work within Indigo. This will now also allow me to create a water level indicator for the tank, where the voltage changes based on the amount of water inside the tank. Happy days :D :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests