Pwm control using mqtt easy esp via openhab

Hi,

I am trying to build a slider in open hab which would give me 0-1023 for my NodeMCU which is running EasyESP and Configured with openhab.

i have tested that It works via HTTP browser request
192.168.8.103/control?cmd=pwM,16,999

but i want that to be control through MQTT Command and openhab UI. But it is not working and when i try to implemenet below code to my openhab… NODEMCU hangs. and needs to reset manually.

My items
Number VARLED {mqtt=">[localbroker:/MASTERSW/pwm/16:command:*:default]"}

My Sitemap
Slider item=VARLED

Please guide me… …i tried alot bu nothing helped.

1 Like

Why are you defining your items file as a Number? Should it not be a Dimmer item?
Also are you altering the ratio of what the NodeMCU receives, to match the ratio that your PWM is expecting? Alternately, I think you can define your sitemap as the following:

Slider item=VARLED step=10 minValue=0 maxValue=1023

to ensure your NodeMCU is not getting a number that’s out of bounds

main.items
Number VARLED {mqtt=">[broker:/MASTERSW/pwm/16:command:*:default]"}

main.sitemap
sitemap main
{
Frame label=“MYROOM”
{
Switch item=MQTTLED label="LED"
Switch item=MQTTLED2 label="LED2"
Slider item=VARLED
}
}

MY ESP STILL HANGS WHEN I MOVE THE SLIDER. PLEASE help… i am not able to help myself…

Did you actually read my original comment?

You also need to get some serial debugging going on your ESP, that’s outputting the value of the MQTT message that’s being received. Like I said, it sounds like it maybe going higher (or lower) than the PWM is capable of. This sounds like a programming issue on your ESP chip rather than an OpenHAB issue.

i have tried everything i don’t if some has successfully used EASYESP with openhab for PWM ? please guide… i tried above methods but not working with EasyESP for PWM.

http command http://192.168.8.103/control?cmd=PWM,14,400 works fine. need MQTT command for 0-1023 for sending to EasyESP node mcu via Openhab

Ok there was issue and Bugs in R120 version of ESP Easy. Now i loaded the lastest build and i am able to get PWM but its only in range of 0-100% using dimmer.

adding sep=10 minValue=0 maxValue=1023 did not helped. is there any other way to give slider range of 0-1023 ?

sitemap
sitemap main
{
Frame label=“KALPESH ROOM”
{
Switch item=MQTTLED label="LED"
Switch item=MQTTLED1 label="LED2"
Slider item=brightness label=“VARIABLE LED PWM”
}
}

items

Switch MQTTLED {mqtt=">[broker:/EASYESP/gpio/4:command:ON:0],>[broker:/EASYESP/gpio/4:command:OFF:1]"}
Switch MQTTLED1 {mqtt=">[broker:/EASYESP/gpio/5:command:ON:0],>[broker:/EASYESP/gpio/5:command:OFF:1]"}

Dimmer brightness {mqtt=">[broker:/EASYESP/PWM/14:command:*:default]"}

1 Like

Can you just do the multiplier in code? So have a standard 0-100 stepping in OH, and in code multiply the received value by 10.23?

1 Like

I was just reading about this here:

HTH.

Yeah totally agree with chimera. Just either calculate 0-100 out to 0-1023 in openHAB or in the ESP unit code itself.

I read this while searching for a solution for some other problems, thus the reply after several months.

So, if you want to to change a percentage to ESP PWM, you can use this mapping table that includes gamme-correction:

// Gamma correction, for details see https://learn.adafruit.com/led-tricks-gamma-correction/
// This table maps [0%-100%] to [0-1023] (PWMRANGE of ESP8266's arduino.h)

const uint16_t /*PROGMEM*/ gamma8[] = {
  0,0,0,0,0,0,0,1,1,1,2,2,3,3,4,5,
  6,7,8,10,11,13,15,17,19,21,24,26,29,32,35,39,
  42,46,50,54,59,63,68,73,79,84,90,96,103,109,116,124,
  131,139,147,155,164,173,182,192,202,212,223,234,245,257,269,281,
  293,307,320,334,348,362,377,392,408,424,441,458,475,493,511,529,
  548,568,587,608,628,650,671,693,716,739,762,786,811,836,861,887,
  913,940,968,996,1023 };

I know this is an old topic but I was wondering if someone could please explain to me what “:command:*:default” mean or stand for?

I have it declared as

Thing mqtt:topic:ESP_Dimmer "ESP_Dimmer" (mqtt:broker:MQTTBroker) @"Home" {

    Channels:

        Type dimmer : LED_Dimmertest "led_dimmerTest" [
            commandTopic="/ESP_Dimmer/PWM/14"
            ]
}

and my item as:

Dimmer LED_Dimmertest "LED_Dimmertest" {channel="mqtt:topic:ESP_Dimmer:LED_Dimmertest"}

and it is working and I am able to send a pwm signal to gpio14 on nodeMCU via the dimmer Item.
Also, if I wanted to send a specific PWM command to an item in a rule file, would I do it something like this?:

itemName.sendCommand("500")

Any tips/suggestion would be greatly appreciated. Thank you.

It is syntax relating to MQTT binding version 1. As you said, it’s an old topic.
In this case it just means pass any Item command as-is to MQTT.

Yes. Try it.

1 Like