Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Appliance monitoring scene 1.0.0

   (0 reviews)

About This File

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:

Appliance monitoring.jpg

 

SCENE DESCRIPTION

This 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:

 

GLOBAL VARIABLES SETUP

"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:

-- get the table from global if not using then delete this line!!!
local jT  = json.decode(fibaro:getGlobalValue("HomeTable"))

"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:

-- enter name of your global variable for monitoring state of appliance and
-- map your values for "On" and "Off"
local applianceStatus        = "WashingMachine";
local applianceStatusMapping = {On="On", Off="Off"};

DEVICE, NOTIFICATION AND USERS SETUP

After 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:

-- APPLIANCE CONTROL DEVICE SETUP -------------------------------------------
-- enter device ID which is used to control appliance and measure power
-- consumption. Do not forget to put this ID in scene header under
-- %% properties
-- 100 power
local deviceID           = 100;
-- enter minimum power in Watt bellow which appliance is stopped or in
-- standby mode
local deviceMinPower     = 2;
-- enter time in minutes after which scene will send message that appliance
-- is done and stopped. This time delay is necessary for many modern washing
-- machines due to electronic drive controls
local deviceStopDuration = 3;
-- enter here "Yes" if you want to switch off appliance when is done and
-- stopped or "No" if you want to leave it on
local deviceTurnOff      = "No";

-- USERS, PUSH AND POPUP NOTIFICATION SETUP ---------------------------------
-- define users to send push messages
local userID   = {jT.ios.wife, jT.ios.mistress};
-- flag for each user; if 1 then send notifications else if 0 do not
-- send notifications. You can add code in function extraUserCodeFirst()
-- where you can change user flags depending on some global variable.
local userFlag = {1, 1};

-- PUSH MESSAGES SETUP ------------------------------------------------------
-- enter push message text for the appliance start and stop event
local pushMessage = {start = "Washing machine is started",
                     stop  = "Washing machine is stopped"};
-- enter "Yes" if you want to receive push notification that appliance
-- started working else put "No"
local pushStart = "No";
-- enter "Yes" if you want to receive push notification that appliance
-- finished working else put "No"
local pushStop  = "Yes";

-- POPUP MESSAGES SETUP -----------------------------------------------------
-- enter popup message text and button caption for the appliance start and 
-- stop
local popupMainTitle         = "WASHING MACHINE";
local popupTimeFormat        = "%H:%M:%S | %d.%m.%Y.";
local popupContentTitleStart = "Washing machine is started";
local popupContentTitleStop  = "Washing machine finished";
local popupContentBodyStart  = "Washing machine is working";
local popupContentBodyOn     = "Washing machine is not turned Off";
local popupContentBodyOff    = "Washing machine is turned Off";
local popupImgUrl            = "";
local popupButtonCaption     = "OK";
-- enter "Yes" if you want to receive popup notification that appliance
-- started working else put "No"
local popupStart = "No";
-- enter "Yes" if you want to receive popup notification that appliance
-- finished working else put "No"
local popupStop  = "No";

It seems a lot but it is actually more of my comments and explanations than real code to setup :-P . 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:

-- EXTRA GLOBAL VARIABLES ---------------------------------------------------
-- here you can add your extra global variables to enhance features of this
-- scene:
-- for all those daddies and momies who work away from home to lower number of 
-- notifications while at work possible values: "Yes", "No"
local dadAway             = "DadAway";
local dadAwayMapping      = {Yes="Yes", No="No"};
local momAway             = "MomAway";
local momAwayMapping      = {Yes="Yes", No="No"};

And 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:

-- EXTRA FUNCTION WHERE YOU CAN ADD YOUR CODE ----------------------------
-- use this function to add code that will be executed before loop is
-- started and push adn popup notifications are sent
function extraUserCodeFirst()
  -- your code goes here
  if dadAway ~= "" then
    if fibaro:getGlobalValue(dadAway) == dadAwayMapping.Yes then
      userFlag[1] = 0;
    end
  end
  if momAway ~= "" then
    if fibaro:getGlobalValue(momAway) == momAwayMapping.Yes then
      userFlag[2] = 0;
    end
  end
  if deBug then logbug("yellow", "User extra code before loop executed") end;
end

 

Please, also check video from @MarcoTorino71:

 

 

 

Edited by Sankotronic
Added video from @MarcoTorino71

 Share



User Feedback

Recommended Comments

@Sankotronic I am getting the following error: 

 

 


[DEBUG] 23:31:26: Appliance monitoring scene started version 1.0 - © 2016 Sankotronic
[DEBUG] 23:31:26: 2020-01-12 23:31:26.310691 [ fatal] Unknown exception: /opt/fibaro/FibaroSceneAPI.lua:155: Assertion failed: Expected string

 

what I am doing wrong? code is below

 

--[[
%% properties
100 power
539 power
539
%% globals
--]]

--[[
-----------------------------------------------------------------------------
-- APPLIANCE MONITORING SCENE -- Washing machine
-----------------------------------------------------------------------------
Copyright © 2016 Zoran Sankovic - Sankotronic. All Rights Reserved.
Version 1.0

-- VERSION HISTORY ----------------------------------------------------------
1.0 - Completely rewritten scene so can be used to monitor any appliance in
      the home or workplace. 

-- COPYRIGHT NOTICE ---------------------------------------------------------
Redistribution and use of this source code, with or without modification, 
is permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. The name of the author may not be used to endorse or promote products 
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY  COPYRIGHT OWNER  "AS IS"  AND ANY  EXPRESS  OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY  AND FITNESS FOR A  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT  SHALL THE AUTHOR  BE  LIABLE  FOR ANY  DIRECT,  INDIRECT, INCIDENTAL, 
SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT NOT LIMITED 
TO, PROCUREMENT  OF SUBSTITUTE  GOODS OR  SERVICES;  LOSS OF USE,  DATA,  OR 
PROFITS;  OR BUSINESS INTERRUPTION)  HOWEVER  CAUSED  AND  ON  ANY THEORY OF 
LIABILITY,  WHETHER  IN  CONTRACT,  STRICT  LIABILITY,  OR  TORT  (INCLUDING 
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-- SCENE DESCRIPTION --------------------------------------------------------
This 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. Bellow you will find part of code for you to setup for
particular appliance and behavior of this scene.

-- LIST OF GLOBAL VARIABLES NEEDED ------------------------------------------
"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!
"applianceStatus" - make predefined global variable with two possible
                    values "On" and "Off". Values can be in your language
                    just map them to values used in this scene. name of
                    global variable is up to you. For example to monitor
                    washing machine you can make global variable named
                    "WashigMachine" adn put that name for applianceStatus
--]]

-- Making sure that only one instance of the scene is running. This is working
-- in 99,99% of the time with Max. running instances set to 4 or more. There
-- are very rare occasions when in very small split of second one instance
-- still didn't stop but another already kick in and then giving warning 
-- notification if Max. running instances is set to 2 or less.
-- There is no other influence to this scene except that annoying warnings in
-- notification area but scene will continue to work properly. Of course you
-- need to leave this code bellow as it is.
if (fibaro:countScenes() > 1) then
  fibaro:abort();
end
    
-- PART OF CODE FOR USERS TO EDIT AND SETUP ---------------------------------

-- GLOBAL VARIABLES ---------------------------------------------------------
-- enter names and value mapping of your global variables or leave as it is
-- and add to variables panel

-- get the table from global if not using then delete this line!!!
--local jT = json.decode(fibaro:getGlobalValue("HomeTable"));

-- enter name of your global variable for monitoring state of appliance and
-- map your values for "On" and "Off"
local applianceStatus        = "WashingMachine";
local applianceStatusMapping = {On="On", Off="Off"};

-- EXTRA GLOBAL VARIABLES ---------------------------------------------------
-- here you can add your extra global variables to enhance features of this
-- scene:

-- APPLIANCE CONTROL DEVICE SETUP -------------------------------------------
-- enter device ID which is used to control appliance and measure power
-- consumption. Don't forget to put this ID in scene header under
-- %% properties
-- 100 power
local deviceID           = 539;
-- enter minimum power in Watt bellow which appliance is stopped or in
-- standby mode
local deviceMinPower     = 0;
-- enter time in minutes after which scene will send message that appliance
-- is done and stopped. This time delay is necessary for many modern washing
-- machines due to electronic drive controls
local deviceStopDuration = 5;
-- enter here "Yes" if you want to switch off appliance when is done and
-- stopped or "No" if you want to leave it on
local deviceTurnOff      = "No";

-- USERS, PUSH AND POPUP NOTIFICATION SETUP ---------------------------------
-- define users to send push messages
local userID   = {554, 500};
-- flag for each user; if 1 then send notifications else if 0 do not
-- send notifications. You can add code in function extraUserCodeFirst()
-- where you can change user flags depending on some global variable.
local userFlag = {1, 1};

-- PUSH MESSAGES SETUP ------------------------------------------------------
-- enter push message text for the appliance start and stop event
local pushMessage = {start = "Washing machine is started",
                     stop  = "Washing machine is stopped"};
-- enter "Yes" if you want to receive push notification that appliance
-- started working else put "No"
local pushStart = "Yes";
-- enter "Yes" if you want to receive push notification that appliance
-- finished working else put "No"
local pushStop  = "Yes";

-- POPUP MESSAGES SETUP -----------------------------------------------------
-- enter popup message text and button caption for the appliance start and 
-- stop
local popupMainTitle         = "WASHING MACHINE";
local popupTimeFormat        = "%H:%M:%S | %d.%m.%Y.";
local popupContentTitleStart = "Washing machine is started";
local popupContentTitleStop  = "Washing machine finished";
local popupContentBodyStart  = "Washing machine is working";
local popupContentBodyOn     = "Washing machine is not turned Off";
local popupContentBodyOff    = "Washing machine is turned Off";
local popupImgUrl            = "";
local popupButtonCaption     = "OK";
-- enter "Yes" if you want to receive popup notification that appliance
-- started working else put "No"
local popupStart = "No";
-- enter "Yes" if you want to receive popup notification that appliance
-- finished working else put "No"
local popupStop  = "Yes";

-- DEBUGGING VARIABLES -----------------------------------------------------
-- setup debugging, true is turned on, false turned off.
local deBug        = true;  -- for showing events as they happen
local exDebug      = false; -- for checking loop counter

-- EXTRA FUNCTION WHERE YOU CAN ADD YOUR CODE ----------------------------
-- use this function to add code that will be executed before loop is
-- started and push adn popup notifications are sent
function extraUserCodeFirst()
  -- your code goes here
  if Jacob ~= "" then
    if fibaro:getGlobalValue(Jacob) == JacobMapping.Yes then
      userFlag[1] = 0;
    end
  end
  if Andy ~= "" then
    if fibaro:getGlobalValue(Andy) == AndyMapping.Yes then
      userFlag[2] = 0;
    end
  end
 
  
  if deBug then logbug("yellow", "User extra code before loop executed") end;
end

-- use this function to add code that will be executed after loop is
-- finished and before sending push and popup notifications
function extraUserCodeLast()
  -- your code goes here
  
   local Jacob             = "JacobPresentstate";
local JacobMapping      = {Yes="Away", No="Home"};
local Andy            = "AndyPresentstate";
local AndyMapping      = {Yes="Away", No="Home"};

  if deBug then logbug("yellow", "User extra code after loop executed") end;
end
-- END OF CODE PART FOR USERS TO EDIT AND SETUP -----------------------------

-- BELLOW CODE NO NEED TO MODIFY BY USER ------------------------------------
-- except if you know what you're doin' :-P

local StartSource = fibaro:getSourceTrigger()
local countdown   = 0;
local version     = "1.0";

function logbug(color, message)
  fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); 
end

-- send push notification
function sendPush(message)
  if (#userID == #userFlag) then
    if #userID > 0 then
      for i = 1, #userID do
        if userFlag == 1 then
          fibaro:call(userID, "sendPush", message); -- Send message to flagged users
          if deBug then logbug("orange", "Push notification sent to user "..fibaro:getName(userID)) end;
        end
      end
    end
  else
    if deBug then logbug("red", "User and flag count is different, not setup correctly. Please check") end;
  end
end

-- send popup notification
function sendPopup(i)
  if i == 1 then
    popupContentTitle = popupContentTitleStart;
    popupContentBody  = popupContentBodyStart;
    popupTypeInfo     = "Info";
    if deBug then logbug("orange", "Popup notification sent: appliance started") end;
  else
    popupContentTitle = popupContentTitleStop;
    if deviceTurnOff == "Yes" then
      popupContentBody = popupContentBodyOff
      if deBug then logbug("Yellow", "Appliance is switched off") end;
    else
      popupContentBody = popupContentBodyOn
    end
    popupTypeInfo     = "Success";
    if deBug then logbug("orange", "Popup notification sent: appliance stopped") end;
  end
  -------------------------------------------
  HomeCenter.PopupService.publish({
      -- title (required)
      title = popupMainTitle,
      -- subtitle(optional), e.g. time and date of the pop-up call
      subtitle = os.date(popupTimeFormat),
      -- content header (optional)
      contentTitle = popupContentTitle,
      -- content (required)
      contentBody = popupContentBody,
      -- notification image (assigned from the variable)
      img = popupImgUrl,
      -- type of the pop-up
      type = popupTypeInfo,
      -- buttons definition
      buttons = { { caption = popupButtonCaption, sceneId = 0 } }
    })
  ---------------------------------------------
end

if ((tonumber(fibaro:getValue(deviceID, 'power')) > deviceMinPower) and (StartSource["type"] == 'property')) then    
  logbug ("green", "Appliance monitoring scene started version "..version.." - © 2016 Sankotronic");
  fibaro:setGlobal(applianceStatus, applianceStatusMapping.On);
  extraUserCodeFirst();
  if pushStart  == "Yes" then sendPush(pushMessage.start) end;
  if popupStart == "Yes" then sendPopup (1) end;
  while true do
    local power = tonumber(fibaro:getValue(deviceID, "power"));
    -- if power is greater than minimum then reset countdown
    if (power > deviceMinPower) then
      countdown = deviceStopDuration;
    else
      if (countdown > 0) then countdown = countdown - 1 end;
    end
    -- if countdown is ended then send notification and turn off
    if (countdown == 0) then
      if fibaro:getGlobalValue(applianceStatus) == applianceStatusMapping.On then
        fibaro:setGlobal(applianceStatus, applianceStatusMapping.Off);
        extraUserCodeLast();
        if pushStop      == "Yes" then sendPush(pushMessage.stop) end;
        if popupStop     == "Yes" then sendPopup (2) end;
        if deviceTurnOff == "Yes" then fibaro:call(deviceID, "turnOff") end;
      end
      logbug ("green", "Appliance monitoring scene Ended");
      -- Kill running scene cause it is done with appliance
      fibaro:abort();
    end
    if deBug then logbug("lightgreen", "Power: " .. power .. "W, Countdown: " .. countdown .. " Min.") end;
    fibaro:sleep(60000);
  end
else
  logbug ("lightgreen", "Appliance monitoring scene started manually and will stop.");
  -- Kill running scene cause it is done with appliance
  fibaro:abort();
end

Link to comment
Share on other sites

Guest Sankotronic

Posted

Hi @amatt ,

 

Have you added "WashingMachine" global variable to HC2? Anyway, you are missing some of the used global variables and that is why you get this error.

 

BTW

Can you please next time send code as TXT document for me to download and check or at least hide it with Spoiler. Thank you.

Link to comment
Share on other sites

Guest Sankotronic

Posted

Hi @amatt ,

 

Still you have to check if name of the global variables that scene use are correctly entered.

Link to comment
Share on other sites

Hello,

 

I'm not a LUA pro but this code will be execute to late. That means you defined the local variables at the end of the script when the device reach for 5 min 0 Watt, but you use them at the start. If I'm right you have to move this code to the beginning of the script.

 

 

image.png.0d3ebb776f09c1afd48b8abfc1576be7.png

 

move this code to  

 

-- EXTRA GLOBAL VARIABLES ---------------------------------------------------
-- here you can add your extra global variables to enhance features of this
-- scene:

local Jacob             = "JacobPresentstate";
local JacobMapping      = {Yes="Away", No="Home"};
local Andy            = "AndyPresentstate";
local AndyMapping      = {Yes="Away", No="Home"};

 

Sankotronic explain this above.

 

 

Then is local deviceMinPower     = 0; I don't know if this works are you sure that the device reach this value?

Edited by FunkFib
Link to comment
Share on other sites

@FunkFib thank you for your response. I did more that code up to your recommended spot. It looks like it is working so far.

 

My washer does get down to 0 but I changed the script to 1.2 watts. either way it will still send it if the washer is at or below 1.2 watts

Link to comment
Share on other sites

Hello Sankotronic,

 

I have added the possibility to switch off the scene with a global Variable 

 

local applianceStatus        = "Trockner";

local applianceStatusMapping = {On="An", Off="Aus"};

 

but I found this in the code:

 

if ((tonumber(fibaro:getValue(deviceID, 'power')) > deviceMinPower) and (StartSource['type'] == "property")) then    
  logbug ("green", "Appliance monitoring scene started version "..version.." - © 2016 Sankotronic");
 -->   fibaro:setGlobal(applianceStatus, applianceStatusMapping.On); <---

 

This part set allways the Status to On and the below if statement is true so its not possible to switch the scene to off.

 

Perhaps I'm wrong. and I don't understand what I can do with this status variable.

 

 

Edit 22.03.2020 21:50 :

 

Ok I'm wrong the variable will be changed by scene to actual status. I search for a way to complete switch the scene off because sometimes in the whool prg the scene starts several times and my wive is not amused.

 

Manuel

Edited by FunkFib
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...