(Last Updated: October 29, 2020)
For those who registered but didn't received the confirmation email, please send an email to support@smarthome.community with the email you used


  • @rafale77 Can this be modified to send an alarm on low battery? This is something that I've been looking at since the OpenLuup migration.

    Something like

    for k, v in pairs(luup.devices) do
      local bat =  luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k)
       if var bat <= 20 then
         $do your alert thing here
       end
    end
    
    

    Cheers

    Sure that won't work as it is, but am I on the right track?

    C


  • Right track, but crossing lanes, a bit. Three things not quite right:

    • battery level variable may not exist
    • even if it does, it's returned as a string
    • you have a spurious 'var' that's been left in from the code you modelled this on

    So...

    for k, v in pairs(luup.devices) do
      local bat = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k)
       if bat and tonumber(bat) <= 20 then
         -- do your alert thing here
       end
    end
    

  • yup @akbooer is right. I do something like this to send a TTS about my iPhone going low on battery while I am at home.


  • My routine to check for battery. I usually do it on first day of month, but if you pass currentday to the function, you'll get a complete report.
    Just omit the parameter and it will notify you of low battery devices only. I usually run it a couple of times per day, unless it's the first day of month, of course 🙂

    function checkBatteries(forceDay)
    	local threshold = 20
    	local counter = 0
    	local deviceNames = "Low battery devices"
    
    	-- override se primo del mese per report completo
    	local currentTime = os.date("*t")
    
    	if tonumber(currentTime.day) == tonumber(forceDay or 1) then
    		threshold = 100
    		deviceNames = "Montly battery check"
    	end
    
    	for deviceNo, d in pairs(luup.devices) do
    		local value = getVar(D_HA, "BatteryLevel", deviceNo)
    		if value ~= nil and value ~= "" and tonumber(value) <= threshold then
    			counter = counter + 1
    			local deviceName = (d ~= nil) and d.description or string.format("Device #%s", tostring(deviceNo))
    
    			deviceNames = string.format("%s\n - %s: %s%s", deviceNames, deviceName, tostring(value), "%")
    		end
    	end
    
    	if counter > 0 then
    		sendAlert(string.format("%s %s", emoji.batteries, deviceNames), nil, true)
    	end
    end
    

  • Thanks, gents!

    C


  • Is there any way of 'actively' to notify when the battery level goes below a given value, without creating a low batter alert for every device? I guess just running this code above every hour or so would be close enough.

    C


  • @CatmanV2

    Depending on how frequently you want to check but... I have gone as far as creating a variable watch on the battery for that particular "k" device.

    Add something like this in your startup lua:

    luup.variable_watch("checkbat", "urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k)
    

    and in that case I would use the function "checkbat" as follow

    function checkbat()
    local bat = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel",k)
    if bat and tonumber(bat) <= 20 then
       -- do your alert thing here
    end
    end
    

  • That’s normally done with a simple scene trigger...?


  • yeah it can be done through a scene as well but if I have a bunch of them, I just create the watches in a batch in my startup lua. Seems faster than using scenes.