Rules Question - Can you do "Calculations" in rules?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Zodiac69
Normal user
Posts: 55
Joined: 13 Jun 2016, 17:20

Rules Question - Can you do "Calculations" in rules?

#1 Post by Zodiac69 » 27 Dec 2020, 10:55

Hi All

I have a rule that decode a mqtt event and split each of the 16 bits to switch a MCP23017 port On/Off, thanks to ThomasB - viewtopic.php?f=4&t=7988#p47122
I would like to display the "Calculated" value on a oled, each bit represent a different value, how can i:
1. Assign a value to the "bit"
2. Sum the value and make it available to display?

Is this possible, or is there another way of doing this?

Z69

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

Re: Rules Question - Can you do "Calculations" in rules?

#2 Post by TD-er » 27 Dec 2020, 13:33

Right now we don't have logic operators like logic and/or, which makes it a bit hard to extract single bits out of values.

As it has been requested a few times before, I will try to add extra commands for div/mod and some other bitwise operators.

Right now you can try to split the number into less values using the existing string operators we already have.

For example %c_2hex%(100000) will replace the "100000" into "186A0"
This can then be split into a smaller number of hex decimals, via https://espeasy.readthedocs.io/en/lates ... #substring
Sadly the position starts from the "most significant" digit, so it is still hard to extract the correct bit as the resulting value of the HEX string may not be of constant length.

So you still may need to do way too much in the rules to extract a bit, which makes a valid point for the need of proper bit extraction commands.

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

Re: Rules Question - Can you do "Calculations" in rules?

#3 Post by TD-er » 27 Dec 2020, 15:18

OK, I took a look at the code and it looked like finding and describing work-around was probably taking longer then implementing it.
So can you have a look at this PR: https://github.com/letscontrolit/ESPEasy/pull/3439 ?

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests