dzVents and multiselector switch.  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
magicduck
Posts: 36
Joined: Sunday 11 February 2018 13:25
Target OS: -
Domoticz version:
Location: Longwy, France
Contact:

dzVents and multiselector switch.

Post by magicduck »

Hello,

I have some selector switch (virtual device) who has Off/Hors-Gel/Eco/Confort.

Here is the code :

Code: Select all

-- Script de gestion du chauffage dans l'extension si jours blanc ou rouges
return {
	on = { 
		devices = {
			idx_edf_color,	-- EDF - Couleur du jour
			idx_edf_tarif,	-- EDF Tarif en cours
			idx_fp_chalet,	-- Fil pilote Chalet
		},
		timer = { 'every minute' },
	},
	data = {
		Etat_Chauffage = { initial = 'dunno'},
	},
	logging = {
		-- level = domoticz.LOG_INFO,
		-- level = domoticz.LOG_ERROR,
		level = domoticz.LOG_DEBUG,
		marker = 'Gestion Chauffage Extension v1.0',
	},
	execute = function(domoticz)
	domoticz.log(" -- Demarrage !", domoticz.LOG_INFO)
	-- Recuperation des etats
	chauffage_ext = domoticz.devices(idx_fp_chalet).state
	edf_tarif     = domoticz.devices(idx_edf_tarif).text
	edf_color     = domoticz.devices(idx_edf_color).text

	-- 
	domoticz.log('Valeur du chauffage : '..chauffage_ext, domoticz.LOG_DEBUG)
	domoticz.log('EDF : ' ..edf_tarif .. ' / ' .. edf_color, domoticz.LOG_DEBUG)

	-- Initialisation de la valeur etat
	if (domoticz.data.Etat_Chauffage == 'dunno') then
		domoticz.log('Data non initialisé',domoticz.LOG_INFO)
		domoticz.data.Etat_Chauffage = chauffage_ext
	end

	if (((edf_color == '(2) Jour Blanc') or (edf_color == '(3) Jour Rouge')) and (edf_tarif == '(2) Heures Pleines')) then
		domoticz.log(' test etat chauffage', domoticz.LOG_DEBUG)
		if (chauffage_ext ~= 'Off') then
			domoticz.log(' -> pas off, on sauvegarde puis on met a off', domoticz.LOG_INFO)
			domoticz.data.Etat_Chauffage = chauffage_ext
			domoticz.devices(idx_fp_chalet).switchOff()
		end
	else
		-- remise du FP a son ancienne valeur
		if (domoticz.data.Etat_Chauffage ~= chauffage_ext) then
			domoticz.log(' -> Heures Creuse, etat ancien : '.. domoticz.data.Etat_Chauffage, domoticz.LOG_INFO)
			domoticz.devices(idx_fp_chatlet).setState(domoticz.data.Etat_Chauffage)
			--domoticz.data.Etat_Chauffage = chauffage_ext
		end

	end
	domoticz.log(" -- Fin !", domoticz.LOG_INFO)
	end
}
Issue is about

Code: Select all

domoticz.devices(idx_fp_chalet).setState(domoticz.data.Etat_Chauffage)
This has been saved from

Code: Select all

domoticz.devices(idx_fp_chalet).state
But I have no idea how to push back the saved state back to this virtual selector.

I have already tried :

Code: Select all

domoticz.devices(idx_fp_chalet).level 
domoticz.devices(idx_fp_chalet).setLevel(domoticz.data.Etat_Chauffage)
And some other stuff, but still have errors... and doesn't seems to work.

Any good hints?
Last edited by magicduck on Tuesday 06 December 2022 18:44, edited 2 times in total.
User avatar
boum
Posts: 130
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: dzVents and multiselector switch.

Post by boum »

you probably should give us the exact error message and the log of the values you pass the functions. It might make the problem more obvious.
have you tried .level and .switchSelector() ? (documentation seems to imply .setLevel takes a percentage, but as I said I have no idea)
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: dzVents and multiselector switch.  [Solved]

Post by waltervl »

Should be
.switchSelector(<[level]|[levelname] >) : Function. Switches a selector switch to a specific level ( levelname or level(numeric) required ) levelname must be exact, for level the closest fit will be picked. See the edit page in Domoticz for such a switch to get a list of the values). Levelname is only supported when level 0 (“Off”) is not removed Supports command options.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest