Page 1 of 1

Public IP email report

Posted: Sunday 10 March 2019 16:03
by Dave21w
Would it be possible to add an option for monitoring your public IP address say every 30 mins (user settable) so in the event it changes domoticz could email you the new address.

Thanks

Dave

Re: Public IP email report

Posted: Sunday 10 March 2019 19:12
by elmortero
I use this dzvents script:

Code: Select all

return {
	on = {
		timer = { 'at *:06', 'at *:32','at 14:21'},
		httpResponses = { 'getip' } -- matches callback string below
	},
	
    execute = function(domoticz, triggerItem)
    local WanIp = domoticz.devices('WanIp')  -- this is a virtual text sensor I created for this script so I can see the IP address
    local prevWanIP = tostring(WanIp.text) -- here we read the current content of the text sensor

		if (triggerItem.isTimer) then
			domoticz.openURL({
				url = 'https://ifconfig.co/json',
				method = 'GET',
				callback = 'getip'
			})
			
		elseif (triggerItem.isHTTPResponse) then

	local response = triggerItem
		if (response.ok and response.isJSON) then
		local dirIP = tostring(response.json.ip)
		if dirIP ~= nil and dirIP ~= prevWanIP then  --check if the current IP is different from what is currently stored in the text sensor
		    dirIP = tostring(dirIP) --convert to string (just in case it is read as other type
	    	    WanIp.updateText(dirIP) --update the text sensor with the new IP
		--here you can add the action you want, I send the IP via telegram to my phone and update dyndns
		end

			else
				print('**getip failed to fetch info')
			end
		end
	end
}