Page 1 of 1

dzVents and multiselector switch.

Posted: Friday 02 December 2022 11:14
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?

Re: dzVents and multiselector switch.

Posted: Friday 02 December 2022 13:01
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)

Re: dzVents and multiselector switch.  [Solved]

Posted: Friday 02 December 2022 13:33
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.