SmartEvse support

Moderator: leecollings

rron
Posts: 240
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: SmartEvse support

Post by rron »

Ok that is clear, The rest off the topics are working good. Again thanks for the effort.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
HvdW
Posts: 525
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Simplified SmartEVSE switch

Post by HvdW »

I wrote a script and created a switch to switch the SmartEVSE module.
The switch is a selector switch in which you add values Off, 6A, 8A, 10A, 13A, 16A
The script:

Code: Select all

return {
	on = {
		devices = {'EV Charging',},
	},
	data = {},
		logging = {
	    -- Level can be domoticz.LOG_INFO, domoicz.LOG_MODULE_EXEC_INFO, domoticz.LOG_DEBUG, domoticz.LOG_ERROR or domoticz.LOG_FORCE
        --level = domoticz.LOG_INFO,
        level = domoticz.LOG_DEBUG,
		marker = '----EV Charging-----',
	},
	
	
	
	execute = function(domoticz, triggerObject)
    -- domoticz.devices(EV Charging).dump()
    local EVSwitch = domoticz.devices('EV Charging')
    if EVSwitch.state == 'Off' then
            domoticz.log('4 EVSwitch set to off  :' .. EVSwitch.state,domoticz.LOG_DEBUG)
            domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.XXX -t "SmartEVSE-5678/Set/CurrentOverride" -m 0')
    elseif EVSwitch.state == '6A' then
            domoticz.log('5 EVSwitch set to 6A  :' .. EVSwitch.state,domoticz.LOG_DEBUG)
            domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.XXX -t "SmartEVSE-5678/Set/CurrentOverride" -m 60')
    elseif EVSwitch.state == '8A' then
            domoticz.log('6 EVSwitch set to 8A  :' .. EVSwitch.state,domoticz.LOG_DEBUG)
            domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.XXX -t "SmartEVSE-5678/Set/CurrentOverride" -m 80')
    elseif EVSwitch.state == '10A' then
            domoticz.log('7 EVSwitch set to 10A  :' .. EVSwitch.state,domoticz.LOG_DEBUG)
            domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.XXX -t "SmartEVSE-5678/Set/CurrentOverride" -m 100')
    elseif EVSwitch.state == '13A' then
            domoticz.log('8 EVSwitch set to 13A  :' .. EVSwitch.state,domoticz.LOG_DEBUG)
            domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.XXX -t "SmartEVSE-5678/Set/CurrentOverride" -m 130')
    elseif EVSwitch.state == '16A' then
            domoticz.log('9 EVSwitch set to 16A  :' .. EVSwitch.state,domoticz.LOG_DEBUG)
            domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.XXX -t "SmartEVSE-5678/Set/CurrentOverride" -m 160')
	end
 end
}
Whilst I was at it I wrote another script to display the SmartEVSE data in a text device:

Code: Select all

--SmartEVSE state

-- Howto at Luftdaten https://www.domoticz.com/forum/viewtopic.php?f=72&t=23406&hilit=luftdaten
-- Call SmartEVSE with http://192.168.2.xxx/settings

return {
	active = true,
	on = {
	    timer = { 'every 1 minutes' },          
		httpResponses = { 'SmartEVSEStateRetrieved' }, -- matches callback string below
	},
	    logging = {
        level = domoticz.LOG_DEBUG,
        marker = '----SmartEVSE state-----',
    },

	execute = function(domoticz, item)

		if (item.isTimer) then
		    local EVSE_Connected = ' '
			domoticz.openURL({
				url = 'http://192.168.2.xxx/settings',
				method = 'GET',
				callback = 'SmartEVSEStateRetrieved'
			})

		elseif (item.isHTTPResponse) then
			if (item.ok and item.isJSON) then 
				domoticz.utils.dumpTable(item.json)   -- dumpTable laat alle waarden zien, mooi voor debugging
                domoticz.log('#1 override current  :' .. item.json.settings.override_current,domoticz.LOG_DEBUG)
                --domoticz.log('#2 Plug connected state  :' .. item.json.evse.connected,domoticz.LOG_DEBUG)
                if item.json.evse.connected == 1 then
                    EVSE_Connected = 'Connected'
                else
                    EVSE_Connected = 'Not Connected'
                end
				domoticz.devices('SmartEVSE state').setIcon(107)
                domoticz.devices('SmartEVSE state').updateText('Current charging level set     ' .. math.floor(item.json.settings.override_current/10) ..' A'.. 
            '\n Charging cable position   ' .. EVSE_Connected ..
            '\n  ')
	        else
				-- oops
				domoticz.log('Error fetching SmartEVSE', domoticz.LOG_DEBUG)
			end
		end
	end
}

Comment the dumptable out when ready as well as change LOG_DEBUG to LOG_ERROR

To complete it here's the automatic charging on sunpower part.

Code: Select all

-- Volvo XC40 solar power charging
-- Auto laden is Dutch for car charging
-- Volvo aangesloten is Dutch for Volvo is plugged in

--[[
Charging speed
16A - 3500 W
15A - 3450 W
14A - 3200 W
13A - 3000 W
12A - 2730 W
11A - 2500 W
10A - 2300 W
9A  - 2000 W
8A  - 1850 W
7A  - 1650 W
6A  - 1440 W
]]--

local switchOnValue         = 1400      -- Watt sunpower level is minimum charching level for SmartEVSE
local switchOffValue        = 500      -- = energy used, >0 to prevent too often switchoff
return {
	on = {
		timer = {'every 2 minutes at daytime'},
		devices = {'Volvo-aangesloten'},
	},
    logging = {
        level = domoticz.LOG_DEBUG,
        -- change LOG_DEBUG to LOG_ERROR to stop logging in the log
        marker = 'XC40 laden op zonnestroom',
    },
	execute = function(domoticz, triggeredItem)
	    -- domoticz.log(domoticz.devices('XC40 battery charge set').dump(),domoticz.LOG_DEBUG)
	    -- domoticz.log(domoticz.devices('XC40-ChargeLevel').dump(),domoticz.LOG_DEBUG)
	    -- domoticz.log(domoticz.devices('Volvo-aangesloten').dump(),domoticz.LOG_DEBUG)
	    -- domoticz.log(domoticz.devices('Volvo-Distance2Home').dump,domoticz.LOG_DEBUG)
	    -- domoticz.devices('Volvo-Distance2Home').dump()
	    -- domoticz.devices('Power').dump()
	    -- domoticz.devices('Auto laden').dump()
	    local current_time =  os.date("%c")
	    local chargeLevelSet = domoticz.devices('XC40 battery charge set').level
	    local chargeLevelActual        = domoticz.devices('XC40-ChargeLevel').nValue -- is een int en niet iets met een komma XC40-ChargeLevel
	    local DistanceFromHome = domoticz.devices('Volvo-Distance2Home').sensorValue
	    local isConnected = domoticz.devices('Volvo-aangesloten').state
	    local SunnyPower = tonumber(domoticz.devices('Power').rawData[6]) 	   -- opbrengst zonnepanelen
	    local PowerConsumption = tonumber(domoticz.devices('Power').rawData[5])  -- power consumption @home
	    local VolvoOpladen = domoticz.devices('Volvo-Opladen').state
	    
        domoticz.log('Volvo charging cable connected  :' .. domoticz.devices('Volvo-aangesloten').state,domoticz.LOG_DEBUG)
        domoticz.log('Volvo distance from home is     :'.. DistanceFromHome ,domoticz.LOG_DEBUG)
        domoticz.log('Volvo opladen is     :'.. VolvoOpladen ,domoticz.LOG_DEBUG)
        domoticz.log('Energy usage from the network   :'.. PowerConsumption ,domoticz.LOG_DEBUG)
        domoticz.log('Energy return to the network   :'.. SunnyPower ,domoticz.LOG_DEBUG)

        -- DistanceFromHome is used to prevent switching when the car is connected to a charger elsewhere
        -- charging on sunpower only if charging is NOT switched on manually
        if DistanceFromHome < 0.35 and isConnected ~= 'Disconnected' and chargeLevelActual < chargeLevelSet and domoticz.globalData.chargingSwitchedManual == 0 then
            -- gaan we laden op zonnestroom
	        -- local PowerConsumption = tonumber(domoticz.devices('Power').rawData[5])  -- power consumption @home
            -- local SunnyPower = tonumber(domoticz.devices('Power').rawData[6]) 	   -- opbrengst zonnepanelen
            -- 6A is 1400 Watt
            -- 8A is 1750 Watt
            -- 10A is 2200 Watt
            -- 13A is 2800 Watt
            -- 16A is 3200 Watt
            -- mosquitto_pub  -h 192.168.2.xxx -t "SmartEVSE-5678/Set/CurrentOverride" -m 111

            if SunnyPower >= switchOnValue then   
                if SunnyPower >= switchOnValue and SunnyPower < 1750 then
                    domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.xxx -t "SmartEVSE-5678/Set/CurrentOverride" -m 60') 
                elseif SunnyPower >= 1750 and SunnyPower < 2200 then
                    domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.xxx -t "SmartEVSE-5678/Set/CurrentOverride" -m 80')  
                elseif SunnyPower >= 2200 and SunnyPower < 2800 then
                    domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.xxx -t "SmartEVSE-5678/Set/CurrentOverride" -m 100') 
                elseif SunnyPower >= 2800 and SunnyPower < 3200 then
                    domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.xxx -t "SmartEVSE-5678/Set/CurrentOverride" -m 130')  
                elseif SunnyPower >= 3200 then
                    domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.xxx -t "SmartEVSE-5678/Set/CurrentOverride" -m 160')                      
                end
                domoticz.data.chargingUsingSunPower = 1
                domoticz.log('# 1 We laden nu op zonnestroom :' ,domoticz.LOG_DEBUG)
                domoticz.log('#2 Teruglevering aan het net is     :'.. SunnyPower ,domoticz.LOG_DEBUG)
                local subject = '#1 We laden nu op zonnestroom !'
                    local message = 
                    ' ' .. current_time .. '\n'.. 
                    'Volvo current battery level is        : ' .. chargeLevelActual        .. '\n' 
                domoticz.notify(subject, message, domoticz.PRIORITY_NORMAL)
            end

            if PowerConsumtion >= switchOffValue then 
                domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.xxx -t "SmartEVSE-5678/Set/CurrentOverride" -m 0')  
                domoticz.log('Stroom van het net is  :'.. PowerConsumption ,domoticz.LOG_DEBUG)
                local subject = '#3 We laden niet langer op zonnestroom !'
                    local message = 
                    ' ' .. current_time .. '\n'.. 
                    'Volvo current battery level is        : ' .. chargeLevelActual        .. '\n' 
                domoticz.notify(subject, message, domoticz.PRIORITY_NORMAL)
            end

            if chargeLevelActual >= chargeLevelSet then
                domoticz.executeShellCommand('mosquitto_pub  -h 192.168.2.xxx -t "SmartEVSE-5678/Set/CurrentOverride" -m 0') 
                local subject = '#3 Zonnestroomladen uit wegens bereiken max. '
                local message = 
                ' ' .. current_time .. '\n'.. 
                'Volvo battery level setting        : ' .. chargeLevelSet .. '\n' ..
                'Volvo battery level state        : ' .. chargeLevelActual        .. '\n' 
                domoticz.notify(subject, message, domoticz.PRIORITY_NORMAL)
            end

            domoticz.log('#8 Laden zonnestroom aan het eind van het script status :',domoticz.LOG_DEBUG)
        end
    end
}
This work leans heavily on the work done by akamming for the Volvo plugin.
Last edited by HvdW on Sunday 29 September 2024 0:06, edited 4 times in total.
Bugs bug me.
rron
Posts: 240
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: SmartEvse support

Post by rron »

Thank you, I will try this on my test system
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
rron
Posts: 240
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: SmartEvse support

Post by rron »

I have a small problem which I cannot solve. If you look at the device screen you can see that "EVEnergyCharged"and "EVTotalEnergyCharged"has a 11 in front of the value 10.649.
If you look at the mqtt explorer you see the right value. I tried to change this in de mapper.json with the multiplier 0.001 but that didn´t solve the problem.
Attachments
Schermafdruk van 2024-11-17 13-59-15.png
Schermafdruk van 2024-11-17 13-59-15.png (204.54 KiB) Viewed 879 times
Schermafdruk van 2024-11-17 13-52-43.png
Schermafdruk van 2024-11-17 13-52-43.png (173.04 KiB) Viewed 879 times
Schermafdruk van 2024-11-17 13-52-09.png
Schermafdruk van 2024-11-17 13-52-09.png (192.27 KiB) Viewed 879 times
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
rron
Posts: 240
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: SmartEvse support

Post by rron »

I´have changed the type to 248 and the subtype to 1. Now the value is good but the instead of kWh it shows Watt.
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest