Page 1 of 1

Solar Daytopper integration with Domoticz

Posted: Tuesday 08 October 2024 21:59
by reinos
Hi there,

I’d like to share some information about my project, Solar Daytopper, and how it integrates with Domoticz.
Solar Daytopper is an app (available for iOS and Android) that lets you compare your solar data with others and compete through gamification. For example, you can earn points and badges when your inverter generates the first watts or when you produce the most kWh in a day. With Solar Daytopper, you can compete with friends, colleagues, or family members in generating solar power.

Below is a screenshot of the app and the Daytopper module (esp32 based - for those without the technical knowledge to fetch solar data from their inverter and post it to the Solar Daytopper API).

Image

The reason I’m posting this is that I’ve received several questions about how to connect Domoticz to the Solar Daytopper API. I previously created a blog post about this topic, but I thought sharing the information here might help even more people.

If you’re reading this, I assume you already know how to create an inverter in your account on the Solar Daytopper app. If not, you can follow the instructions here.

Once your inverter is set up in the Solar Daytopper app, you can use the following DZevent snippet to post your solar data to the Solar Daytopper API whenever your solar device is updated.

Code: Select all

local solarDeviceId = 40 <-- Your solar device id
local daytopperApiKey = "" <-- Your Daytopper API key

return {
	on = {
		devices = {
			solarDeviceId,
		},
		httpResponses = {
			'triggerDaytopperLogin',
			'triggerDaytopperPost'
		},
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'Daytopper',
	},
	execute = function(domoticz, item)
	 	local solarDevice = domoticz.devices(solarDeviceId)
		local total = solarDevice.WhTotal;
		local current = solarDevice.actualWatt;

		if (item.isHTTPResponse) then
			
			if (item.ok) then
				if (item.isJSON) then
					local result = item.json

					if (item.trigger == 'triggerDaytopperLogin') then
					    domoticz.log('Sending data to Daytopper API...')
					    domoticz.openURL({
            				url = 'https://api.solar-daytopper.com/solar',
            				method = 'POST',
            				callback = 'triggerDaytopperPost',
            				headers = {
                                Authorization = "Bearer " .. result.token,
                                ['Content-Type'] = "application/json"
                            },
            				postData = "{\"total\":" .. total .. " ,\"current\": " .. current .."}"
            			})
					elseif (item.trigger == 'triggerDaytopperPost') then
					    domoticz.log(result)
						domoticz.log('Succes sending data')
					end
					
				else
					domoticz.log('HTTP is not json', domoticz.LOG_ERROR)
				end
			else
				domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
				domoticz.log(item, domoticz.LOG_ERROR)
			end
		else
			domoticz.openURL({
				url = 'https://api.solar-daytopper.com/device/login',
				method = 'POST',
				callback = 'triggerDaytopperLogin',
				postData = {
		            token = daytopperApiKey
		        }
			})
		end

	end
}
In this snippet you'll find at the top 2 variables that you'll need to fill with your own details. solarDeviceId is the deviceId of your solar device in domoticz and daytopperApiKey is a token that you can get from your inverter page inside the Solar Daytopper app. Once you filled in those 2 variables, you are good to go. As of now, when the Solar device in Domoticz is updated, it will send your data also to the Solar Daytopper API.

If you have questions about this integration or about the project, feel free to leave a comment.

Happy Solar competing!