Automatic watering system | Rule is not working

Hey guys,

I’m creating a Automatic Watering System for my plants. I’ve installed a Soil Moisture Sensor and a Pump to an NodeMCU with ESPEasy on it. So far, I can regulate the pump by a switch in BasicUI and I can see the state of the Moisture Sensor (wet, medium or dry).

My goal is to install an automatic system that automatically activates the pump when a threshold value is exceeded. I did a lot of research and tried to write a rule for it. Unfortunately it has not worked yet.

Thats my rule until now. Very simple but it doesnt work.

 rule "Water System"
    when   
            Item Client1_MoistureSens changed
    then   
        logInfo("Test", Client1_MoistureSens.state.toString)
        if(Client1_MoistureSens.state > 600){
            sendCommand(Pump1, ON) }
            
    end

I would be very happy about your help!

Thanks guys!

Greetings, Sinic!

It would be really helpful to see the events.log entry for your Item changing.
Also, the output (if any) from your logInfo() in your openhab.log

I would suspect a UoM problem, but there is not enough info given to tell

**2019-11-18 12:49:29.622 [vent.ItemStateChangedEvent] - Client1_MoistureSens changed from 854.0 to 853.0

==> /var/log/openhab2/openhab.log <==

2019-11-18 12:49:29.645 [INFO ] [.eclipse.smarthome.model.script.Test] - 853.0

2019-11-18 12:49:32.603 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:35.606 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:38.608 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:41.607 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:44.605 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:47.605 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:50.606 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:53.607 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:56.602 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:49:59.606 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:50:02.605 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.

2019-11-18 12:50:05.601 [WARN ] [.profiles.RegexTransformationProfile] - Please specify a function and a source format for this Profile in the 'function' and 'sourceFormat' parameters. Returning the original state now.**

I think there is no unit. It is just a number between 0-1024.

Okay, let’s treat it as a number then

if( (Client1_MoistureSens.state as Number) > 600) {

You have some other issue - looks like a profile associated with some Item channel.

Ok, add more logging:

rule "Water System"
when   
    Item Client1_MoistureSens changed
then   
    logInfo("Test", Client1_MoistureSens.state.toString)
    if(Client1_MoistureSens.state > 600) {
        logInfo("Test", "Moisture over 600, sending command...")
        Pump1.sendCommand(ON)
        logInfo("Test", "Command sent")
    }
end

Please provide your item definition and channel setting for Pump1, please

Alright, I dont get the logInfo you added. So something is wrong with the if loop.

I added the Item in PaperUI, so i cant find code of the item definition or Channel setting.

Is that enough?

Seems to work now.
I added “as Number” into the if loop.

if(Client1_MoistureSens.state as Number > 600) {

Please tick the solution post. Thanks