Solar Daytopper integration with Domoticz

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Post Reply
reinos
Posts: 5
Joined: Tuesday 02 June 2020 21:50
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Solar Daytopper integration with Domoticz

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

Who is online

Users browsing this forum: No registered users and 1 guest