_:na3dc75f24cfb44d79a261cc6fb908020xb0
<http://schema.org/description>
"Holidays are almost here! So here is one more gift for you! Just maybe you will find it useful and it looks like this in HC webGUI:\n \n\n\n\t\n \n\n\n\t \n \n\n\n\tSCENE DESCRIPTION\n \n\n\n\tThis scene can monitor any appliance for power consumption and send push and/or popup notification when appliance start working and/or when it is finished. You can also select to switch it off when is done or leave it under power. There are more and more smart appliances on the market but still suffering from \"baby\" problems. We also buy Candy washing machine with WiFi and smart app but it just refuses to connect, or if I manage to connect it disconnects itself after one wash. No need to mention that manufacturers of such appliances like to hide API. Because of that we are still using benefits of smart plugs and relay modules to monitor our appliances. So this is how this scene works. It is triggered by power consumption from smart plug or relay module to which appliance is connected. It is possible to set minimum power in watt and duration for how long will scene run until recognizes that appliance is finished. There are only two global variables to be defined. One is already known \"HomeTable\" and another one with name up to you which is set while appliance is working and reset when is finished as explained bellow:\n \n\n\n\t \n \n\n\n\tGLOBAL VARIABLES SETUP\n \n\n\n\t\"HomeTable\"       - predefined global variable table with device and scene IDs. Recommended to use since z-wave devices can change their ID with re-inclusion and then is necessary  to edit only scene which make this table and only device ID in scene headers. Much less time and effort is needed than without that option! But if you don't use this feature then you MUST delete following lines from scene:\n \n\n\n-- get the table from global if not using then delete this line!!!\nlocal jT  = json.decode(fibaro:getGlobalValue(\"HomeTable\"))\n\n\n\t\"applianceStatus\"   - you can use any name like \"WashingMachine\" or \"DishWasher\" depending on appliance you plan to monitor. There are two values \"On\" and \"Off\" that you can map with your values and then setup in scene code like this:\n \n\n\n-- enter name of your global variable for monitoring state of appliance and\n-- map your values for \"On\" and \"Off\"\nlocal applianceStatus        = \"WashingMachine\";\nlocal applianceStatusMapping = {On=\"On\", Off=\"Off\"};\n\n\n\tDEVICE, NOTIFICATION AND USERS SETUP\n \n\n\n\tAfter setting up global variables you still need to setup several things like deviceID (ID number of smart plug or relay module), deviceMinPower which defines under what power in watt device stopped working and is in standby, some text for push and popup notifications and you can start using this scene to monitor your appliance. See bellow setup example for washing machine:\n \n\n\n-- APPLIANCE CONTROL DEVICE SETUP -------------------------------------------\n-- enter device ID which is used to control appliance and measure power\n-- consumption. Do not forget to put this ID in scene header under\n-- %% properties\n-- 100 power\nlocal deviceID           = 100;\n-- enter minimum power in Watt bellow which appliance is stopped or in\n-- standby mode\nlocal deviceMinPower     = 2;\n-- enter time in minutes after which scene will send message that appliance\n-- is done and stopped. This time delay is necessary for many modern washing\n-- machines due to electronic drive controls\nlocal deviceStopDuration = 3;\n-- enter here \"Yes\" if you want to switch off appliance when is done and\n-- stopped or \"No\" if you want to leave it on\nlocal deviceTurnOff      = \"No\";\n\n-- USERS, PUSH AND POPUP NOTIFICATION SETUP ---------------------------------\n-- define users to send push messages\nlocal userID   = {jT.ios.wife, jT.ios.mistress};\n-- flag for each user; if 1 then send notifications else if 0 do not\n-- send notifications. You can add code in function extraUserCodeFirst()\n-- where you can change user flags depending on some global variable.\nlocal userFlag = {1, 1};\n\n-- PUSH MESSAGES SETUP ------------------------------------------------------\n-- enter push message text for the appliance start and stop event\nlocal pushMessage = {start = \"Washing machine is started\",\n                     stop  = \"Washing machine is stopped\"};\n-- enter \"Yes\" if you want to receive push notification that appliance\n-- started working else put \"No\"\nlocal pushStart = \"No\";\n-- enter \"Yes\" if you want to receive push notification that appliance\n-- finished working else put \"No\"\nlocal pushStop  = \"Yes\";\n\n-- POPUP MESSAGES SETUP -----------------------------------------------------\n-- enter popup message text and button caption for the appliance start and \n-- stop\nlocal popupMainTitle         = \"WASHING MACHINE\";\nlocal popupTimeFormat        = \"%H:%M:%S | %d.%m.%Y.\";\nlocal popupContentTitleStart = \"Washing machine is started\";\nlocal popupContentTitleStop  = \"Washing machine finished\";\nlocal popupContentBodyStart  = \"Washing machine is working\";\nlocal popupContentBodyOn     = \"Washing machine is not turned Off\";\nlocal popupContentBodyOff    = \"Washing machine is turned Off\";\nlocal popupImgUrl            = \"\";\nlocal popupButtonCaption     = \"OK\";\n-- enter \"Yes\" if you want to receive popup notification that appliance\n-- started working else put \"No\"\nlocal popupStart = \"No\";\n-- enter \"Yes\" if you want to receive popup notification that appliance\n-- finished working else put \"No\"\nlocal popupStop  = \"No\";\n\n\n\tIt seems a lot but it is actually more of my comments and explanations than real code to setup  . Just to mention that scene has two functions where you can add your own code to do something. Function extraUserCodeFirst() is executed before sending push/popup notification that appliance is started and function extraUserCodeLast() is executed just before sending push/popup notification that appliance is finished and stopping scene. I use them too   For example I alway add code to change flags to whom push messages will be sent in function extraUserCodeFirst(). First I add two global variables under -- EXTRA GLOBAL VARIABLE SETUP --------- section of the code:\n \n\n\n-- EXTRA GLOBAL VARIABLES ---------------------------------------------------\n-- here you can add your extra global variables to enhance features of this\n-- scene:\n-- for all those daddies and momies who work away from home to lower number of \n-- notifications while at work possible values: \"Yes\", \"No\"\nlocal dadAway             = \"DadAway\";\nlocal dadAwayMapping      = {Yes=\"Yes\", No=\"No\"};\nlocal momAway             = \"MomAway\";\nlocal momAwayMapping      = {Yes=\"Yes\", No=\"No\"};\n\n\n\tAnd then I add simple code to change userFlags in function extraUserCodeFirst() if we are at work and don't want to be disturbed by push messages from our Angelina:\n \n\n\n-- EXTRA FUNCTION WHERE YOU CAN ADD YOUR CODE ----------------------------\n-- use this function to add code that will be executed before loop is\n-- started and push adn popup notifications are sent\nfunction extraUserCodeFirst()\n  -- your code goes here\n  if dadAway ~= \"\" then\n    if fibaro:getGlobalValue(dadAway) == dadAwayMapping.Yes then\n      userFlag[1] = 0;\n    end\n  end\n  if momAway ~= \"\" then\n    if fibaro:getGlobalValue(momAway) == momAwayMapping.Yes then\n      userFlag[2] = 0;\n    end\n  end\n  if deBug then logbug(\"yellow\", \"User extra code before loop executed\") end;\nend\n\n\n\t \n \n\n\n\tPlease, also check video from @MarcoTorino71:\n \n\n\n\t \n \n\n\n\t\n\t\t\n\t\n\n\n\n\t \n \n\n\n\t \n "
<https://forum.fibaro.com/files/file/6-appliance-monitoring-scene/?tab=comments#comment-31>