[SOLVED] Rules to control LED according to the temperature values

Platform information:
Hardware: Raspberry Pi 4
openHAB version: OpenHAB 2.5
I am trying to control LED according to the temperature
for eg: If the temperature is above 20 the LED should turn on else should turn off

items file:

Number:Temperature “Current temperature [%.1f %unit%]” { channel=“mqtt:topic:b8cf2dea:temperature” }

//Number:Dimensionless “Current atmospheric humidity [%.1f %unit%]” { channel=“mqtt:topic:b5b108e6:humidity” }

Switch:DemoSwitch “Demo Switch” {channel=“mqtt:topic:5103c7cc:ESP32Switch”}

rules file:

rule “Led Control With Temperature”


Item Temperature received command


if (receivedCommand < 20)


  sendCommand(DemoSwitch, OFF)




  sendCommand(DemoSwitch, ON)



this is my items and rules file.

If the temperature increases it is not getting updated in the BASICUI.
for it I used
rule “Set room temperatures”


System started or

Time cron “5 * * * * ?”


var thingStatusInfo = getThingStatusInfo(“mqtt:topic:b8cf2dea:temperature”)


but still its not working.
Someone please do help me on this issue

Thanks in advance

What makes you think your sensor Item receives commands? That would be unusual.

You can look in your events.log to see what, if anything, is happening to your Item in terms of updates and commands.

That’s a very strange thing to do. A Thing status isn’t going to be a data value from your sensor. It’s going to “ONLINE” or “UNAVAILABLE” or something. You can’t just make the syntax up.
Getting your binding configuration correct is the way to get data from device to Item.

Your item file as well as your rule file would call for several errors in the log file (tail log).
Look at your logfile!! (or tail log).

Second, your items are wrong. Please read the doc about how to create items.
I´ll not give you the full answer here, cause you really need to re-read the docs.
A small hint though:
Whatever happens after Number and Switch in these two items are wrong!

Number:Temperature “Current temperature [%.1f %unit%]” { channel=“mqtt:topic:b8cf2dea:temperature” }
Switch:DemoSwitch “Demo Switch” {channel=“mqtt:topic:5103c7cc:ESP32Switch”}

Third, You got your general rule understanding wrong as well.
A Temperature sensor can not receive a command. It makes no sense. Temperature will change its value of the temperature reading. (That is another small hint for your rule. Notice the bold word).

Please feel free to ask… But at least look in your logfile and read the docs. Then ask if there are things you dont understand. I dont mind helping. But in your case, you desperately need to re-read how to create items first.
Afterwards you need to understand how and why things are triggering in rules.

Again - Notice my hints for you. They will help you in understanding when you have read the docs again, I´m sure!.