MQTTImport and use of formula

Moderators: BertB, rtenklooster, Voyager, Stuntteam, Martinus

Post Reply
Message
Author
wim16
Normal user
Posts: 25
Joined: 01 May 2017, 20:35

MQTTImport and use of formula

#1 Post by wim16 » 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?

grovkillen
Normal user
Posts: 816
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: MQTTImport and use of formula

#2 Post by grovkillen » 11 Jan 2018, 15:15

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.
Author of ESP Easy Flasher [use this for flash and wifi setup at flash time]
Author of ESP Easy Webdumper [use this for easy screendumping of your units]
For my private projects: https://testoftimes.com

wim16
Normal user
Posts: 25
Joined: 01 May 2017, 20:35

Re: MQTTImport and use of formula

#3 Post by wim16 » 11 Jan 2018, 15:56

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

Domosapiens
Normal user
Posts: 62
Joined: 06 Nov 2016, 13:45

Re: MQTTImport and use of formula

#4 Post by Domosapiens » 11 Jan 2018, 17:07

Vaguely remember this ... using (...)

Code: Select all

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

wim16
Normal user
Posts: 25
Joined: 01 May 2017, 20:35

Re: MQTTImport and use of formula

#5 Post by wim16 » 11 Jan 2018, 23:00

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

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests