Rules If statment String

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Sjuul
New user
Posts: 4
Joined: 12 Jan 2023, 17:27

Rules If statment String

#1 Post by Sjuul » 30 Aug 2023, 10:05

Hello,

I'am busy to connect my airco to ESP-Easy receiving data string works great.
The mode of the airco is transferred in a string like "FAN"
Now I try to make in the rules of ESP-Easy an if statement with this string see the code below

Code: Select all

If [Airco2#mode] = 'FAN'
 SendToHTTP 192.168.1.100,8080,/json.htm?type=command&param=switchlight&idx=384&switchcmd=Set%20Level&level=10
Endif
This doesn't work,

Has someone any suggestions to send the HTTP command when the "Fan" string is received?

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules If statment String

#2 Post by Ath » 30 Aug 2023, 10:11

ESPEasy does not support processing string values in rules like that at this time.

How are you receiving those values?
Can they be replaced by numerical values on the sending side? As those can be handled by ESPEasy.
/Ton (PayPal.me)

Sjuul
New user
Posts: 4
Joined: 12 Jan 2023, 17:27

Re: Rules If statment String

#3 Post by Sjuul » 30 Aug 2023, 11:57

Below the string i recieved.

Airco2#settings=`{'roomTemperature':19.0,'wideVane':'<<','power':'OFF','mode':'FAN','fan':'1','vane':'1','iSee'

As you can see there are some numbers but not for everthing.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules If statment String

#4 Post by TD-er » 30 Aug 2023, 12:09

How do you receive this string?
Via MQTT?

Sjuul
New user
Posts: 4
Joined: 12 Jan 2023, 17:27

Re: Rules If statment String

#5 Post by Sjuul » 30 Aug 2023, 13:09

It comes from "HwSerial port 0" Port to GPIO1 and GPIO3

I use this plugin https://espeasy.readthedocs.io/en/lates ... /P093.html

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules If statment String

#6 Post by Ath » 30 Aug 2023, 14:46

Well, you can use the substring function (docs) and indexof function (just below the substring function in the docs) to find and extract the value, into another indexof to find some known values, and use that for comparisons, something like this:
(Be prepared that this isn't very efficient, of well designed yet, just dumping my brainfart :lol:)

Code: Select all

on airco2#settings=* do // use the asterisk to allow non-numeric 1st argument
  let,1,{indexof:mode:"%eventvalue1%"} // Start position of word: mode
  let,2,{indexof:FAN:{substring:%v1%+8:%v1%+11:%eventvalue1%}} // TODO: Check offsets
  if %v2%>-1
    SendToHTTP 192.168.1.100,8080,/json.htm?type=command&param=switchlight&idx=384&switchcmd=Set%20Level&level=10
  endif
endon
Disclaimer: Air code, untested
Edit: Fix some typos
/Ton (PayPal.me)

Sjuul
New user
Posts: 4
Joined: 12 Jan 2023, 17:27

Re: Rules If statment String

#7 Post by Sjuul » 30 Aug 2023, 16:08

Thanks Ath,

This gives me an eye opener.
The plugin 0092 can give also sort value [Airco2#mode] returns only FAN
Just after the position you mentioned in the online help I found the function {equals:<string1>:<string2>}

Code: Select all

 If {equals:[Airco2#mode]:FAN} = 1
  SendToHTTP 192.168.1.100,8080,/json.htm?type=command&param=switchlight&idx=384&switchcmd=Set%20Level&level=10 //10 = Ventileren in Domoticz
 endif

User avatar
Ath
Normal user
Posts: 3522
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules If statment String

#8 Post by Ath » 30 Aug 2023, 16:51

Ah, yes, that's much easier. Don't have any experience with this plugin :? though I have added that feature to get all values, and wrote the documentation (here). :lol:
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 30 guests