Run event based on device power usage in watts

Moderator: leecollings

Post Reply
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Run event based on device power usage in watts

Post by ben53252642 »

Sharing my Lua script to do this in Domoticz, edit as needed for your setup.

In the below script if the washing machines power usage exceeds 4 watts an event will run once, if it falls below 4 watts another event will run once.

Code: Select all

commandArray = {}

 -- Change Watt Device value to number and remove the word Watt
wattdevice = otherdevices_svalues['Washing Machine / Dryer Watts']
function stripchars(str, chrs)
   local s = str:gsub("["..chrs.."]", '')
   return s end
wattvalue = stripchars( wattdevice, " Watt" )

if (uservariables["WashingMachineState"] == 'notinuse' and tonumber(wattvalue) >= 4 ) then
commandArray['Variable:WashingMachineState'] = 'inuse'
os.execute ('sh /domoticz/speak.sh "speaker2 I am ready to wash your clothes."')
end

if (uservariables["WashingMachineState"] == 'inuse' and tonumber(wattvalue) <= 4 ) then
commandArray['Variable:WashingMachineState'] = 'notinuse'
os.execute ('sh /domoticz/speak.sh "speaker2 The washing is finished."')
end

return commandArray
It uses a user variable which you will need to manually create prior to running the script, see below screenshot.
Screen Shot 2016-07-02 at 1.27.55 PM.png
Screen Shot 2016-07-02 at 1.27.55 PM.png (148.55 KiB) Viewed 1844 times
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: Run event based on device power usage in watts

Post by papoo »

thanks
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: Run event based on device power usage in watts

Post by papoo »

can you post your speak.sh?
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Run event based on device power usage in watts

Post by ben53252642 »

Sure, I use Tasker and AutoRemote on Android to speak messages. Simply install AutoRemote on Android and go to the URL it tells you to get the API key for your device.

Then go into Tasker

1) Add an event, choose plugins, auto remote, and set the message filter to: speaker

2) Add a task to the event, choose alert, say then enter %arcomm as the text to say.

Exit tasker and save, then re-open it (you can set it to automatically start at device boot, it's quite reliable.

To call a specific device speaker from linux bash the command would be:

./speak.sh "speaker2 hello world"

I've also left some code I am not using at the moment but may be of use at the bottom of this script which can enable audio output from the Domoticz device itself using a range of text to speech engines (if you have speakers connected).

Code: Select all

#!/bin/sh

# Send to all Speaker Clients
case $1 in allspeakers*)
cd /domoticz
# Google GCM Speakers
./speak.sh "speaker2 $message"
./speak.sh "speaker3 $message"
esac

# Main Bathroom Tablet Speaker Client
case $1 in speaker2*)
part1=$(echo speaker=:="$1" | sed -e 's/\<speaker2\>//g')
part2=$(echo "$part1" | sed 's/ /%20/g')
curl "https://autoremotejoaomgcd.appspot.com/sendmessage?key=ENTERAPIKEYHERE&message="$part2""
esac

# Kitchen Tablet Speaker Client
case $1 in speaker3*)
part1=$(echo speaker=:="$1" | sed -e 's/\<speaker3\>//g')
part2=$(echo "$part1" | sed 's/ /%20/g')
curl "https://autoremotejoaomgcd.appspot.com/sendmessage?key=ENTERAPIKEYHERE&message="$part2""
esac

# ------------------------------------------------

#flite -voice kal16 -t "$1"
#pico2wave -w=temp.wav "$1"
#swift -n David -p audio/sampling-rate=16000 "$1" -o /wave_files/localspeaker.wav
#aplay /wave_files/localspeaker.wav
##pico2wave --lang=en-GB -w /wave_files/localspeaker.wav "$message"
Last edited by ben53252642 on Saturday 02 July 2016 11:58, edited 2 times in total.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: Run event based on device power usage in watts

Post by papoo »

great
thanks
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Run event based on device power usage in watts

Post by ben53252642 »

If your using Z-Wave don't forget to increase the rate that the device sends its status to Domoticz

I use 2 seconds for most devices, they send the power in watts to Domoticz every 2 seconds.
Screen Shot 2016-07-02 at 8.02.36 PM.png
Screen Shot 2016-07-02 at 8.02.36 PM.png (87.98 KiB) Viewed 1796 times
This time allows me to do things such as (I recently purchased a document shredder), when I shred a document Z-Wave detects the power increase in watts from the Shredder and I get a verbal announcement "Shredding complete.". :D

If 2 seconds is not quick enough you may use 1 second in some cases although you want to keep this to a minimum due to the increase in traffic over the Z-Wave network.

I've found it's possible to turn a lot of "dumb" devices into smart devices simply by looking at their power consumption in near realtime.

Some devices I've automated using power consumption include:
  • Washing Machine / Dryer
    Dishwasher
    Shredder
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest