Page 1 of 1

MQTTImport and use of formula

Posted: 11 Jan 2018, 15:09
by wim16
I am using MQTTImport to set a dimmer level (PWM) using MQTT. This works fine as long as I put the PWM dutycycle (1..1024) in the MQTT message payload.
This means that the controller (Domoticz) has to know the range of PWM-levels and convert the dimmer level (0-100%) to PWM.
I'd rather have this conversion done in ESPEasy because the max PWM level is also depending on the type of PWM (native or PCA9685).
I tried to use the formula in the device setting but this seems to be ignored by the plugin. I also tried to do the math in rules (see below) but that does not seem to work either; the PWM level is set to the input level and ignores the formula.

Code: Select all

on DimmerImport#Level do
   PWM,14,[DimmerImport#Level]*1024/100,1250
endon
Any ideas on how to implement this?

Re: MQTTImport and use of formula

Posted: 11 Jan 2018, 15:15
by grovkillen
wim16 wrote: 11 Jan 2018, 15:09 I am using MQTTImport to set a dimmer level (PWM) using MQTT. This works fine as long as I put the PWM dutycycle (1..1024) in the MQTT message payload.
This means that the controller (Domoticz) has to know the range of PWM-levels and convert the dimmer level (0-100%) to PWM.
I'd rather have this conversion done in ESPEasy because the max PWM level is also depending on the type of PWM (native or PCA9685).
I tried to use the formula in the device setting but this seems to be ignored by the plugin. I also tried to do the math in rules (see below) but that does not seem to work either; the PWM level is set to the input level and ignores the formula.

Code: Select all

on DimmerImport#Level do
   PWM,14,[DimmerImport#Level]*1024/100,1250
endon
Any ideas on how to implement this?

You can always look in the log and see the output of your math.

Re: MQTTImport and use of formula

Posted: 11 Jan 2018, 15:56
by wim16
Well, I did and it just takes the first value of the formula instead of performing the math.
However if I set a dummy taskvalue using the same formula it does work.

Code: Select all

IMPT : [DimmerImport#Level] : 36.00
EVENT: DimmerImport#Level=36.00
ACT  : PWM,14,36*1024/100,1250
SW   : GPIO 14 Set PWM to 36

Re: MQTTImport and use of formula

Posted: 11 Jan 2018, 17:07
by Domosapiens
Vaguely remember this ... using (...)

Code: Select all

on DimmerImport#Level do
   PWM,14,([DimmerImport#Level]*1024/100),1250
endon

Re: MQTTImport and use of formula

Posted: 11 Jan 2018, 23:00
by wim16
I tried with the same result. But after some more study of the wiki I think I have to use a dummy device as an intermediate store.
It looks like this is working:

Code: Select all

on DimmerImport#Level do
   TaskValueSet, 2,1,[DimmerImport#Level]*1024/100  // set PWM#Dummy
endon

on PWM#Dummy do
  PWM,14,%eventvalue%,1250
endon