Public IP email report

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
Dave21w
Posts: 382
Joined: Sunday 29 November 2015 21:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: UK
Contact:

Public IP email report

Post 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
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Public IP email report

Post 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
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest