dzVents script + IFTTT for Withings scale

Moderator: leecollings

Post Reply
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

dzVents script + IFTTT for Withings scale

Post by felix63 »

Using the new dzVents 3.0 functionality I created a script to process measurements from a Withings Scale.

The script requires two virtual devices one of type weight (weegschaal) and one of type percentage (vetpercentage).

The IFTTT:
In IFTTT create an applet using Withings and Webhooks:
If New Body Scale measurement by [USER], then Make a web request

In the Webhook make a GET request for the following URL (change to your domoticz URL):

Code: Select all

https://user:[email protected]/json.htm?type=command&param=customevent&event=Withings&data=[{"gewicht": {{WeightKg}}},{"vet": {{FatPercent}}}]
The script:

Code: Select all

return {

	-- 'active' controls if this entire script is considered or not
	active = true, -- set to false to disable this script

    logging = {
        level = domoticz.LOG_INFO,                                             -- Max. one level can be active; comment the others
        -- level = domoticz.LOG_ERROR,
        -- level = domoticz.LOG_DEBUG,
        -- level = domoticz.LOG_MODULE_EXEC_INFO,
        marker = "Withings"                                                      
    },

	-- trigger
	on = {
		customEvents = { 'Withings' }
	},

	-- actual event code
	execute = function(domoticz, device)
	    if device.data[1] then
    	        local gewicht = tonumber(device.data[1].gewicht)
	        domoticz.log('Nieuwe weging, gewicht: ' .. gewicht, domoticz.LOG_INFO)
               domoticz.devices('Weegschaal').updateWeight(gewicht)
          end
          if device.data[2].vet then
	        local vet = tonumber(device.data[2].vet)
	        domoticz.log('Nieuwe weging, Vet%: ' .. vet, domoticz.LOG_INFO)
                domoticz.devices('Vetpercentage').updatePercentage(vet)
          end
	end
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest