Constants in Rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Burberius
New user
Posts: 2
Joined: 24 Nov 2023, 22:25

Constants in Rules

#1 Post by Burberius » 24 Nov 2023, 22:31

Hi

I have a little sensor module that sends its values to some http service as a given time.
I use rules for that but the "code" doesn't look that nice. I would prefere to define the apikey of the http service and also the execution time at the beginning of the rules to make it easier to configure/change them.
Something like:

Code: Select all

def apikey=abc123
def sendtime=07:00

On Clock#Time=All,%sendtime% do
  SendToHTTP www.pushsafer.com,80,/api?k=%apikey%&i=81&t=%sysname%%20Status&m={urlencode:"Temperature [Sensor#Temperature]°C Humidity [Sensor#Humidity]% Dew Point %c_dew_th%([Sensor#Temperature],[Sensor#Humidity])°C at time: %lcltime%"}
endon
Is that somehow possible?

Bye, Burb

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

Re: Constants in Rules

#2 Post by TD-er » 24 Nov 2023, 22:37

You can use the command 'let' to store variables and then access them via [int#N] or [var#N] to access variable nr N.

But those can only be numerical, not a string.

Burberius
New user
Posts: 2
Joined: 24 Nov 2023, 22:25

Re: Constants in Rules

#3 Post by Burberius » 28 Nov 2023, 18:40

Is there a possibility to get the name of a value from a dummy controller?
Then I could create a controller apikey and set the key as the value name.

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Constants in Rules

#4 Post by chromo23 » 28 Nov 2023, 19:49

Burberius wrote: 28 Nov 2023, 18:40 Then I could create a controller apikey and set the key as the value name.
But why not making then for every API a sperate entry and just set a number? e.g.:

Code: Select all

let,1,1


Like

Code: Select all

On Clock#Time=All,[var#2]:[var#3] Do // I can´t remember if this worked but i think so...
 If [var#1]=1
  SendToHTTP www.pushsafer.com,80,/api?k=<key1>...
 Elseif [var#1]=2
  SendToHTTP www.pushsafer.com,80,/api?k=<key2>...
 Elseif [var#1]=3
  SendToHTTP www.pushsafer.com,80,/api?k=<key3>...
 Elseif [var#1]=4
  SendToHTTP www.pushsafer.com,80,/api?k=<key4>...
 Elseif [var#1]=5
  SendToHTTP www.pushsafer.com,80,/api?k=<key5>...
 Endif
Endon

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

Re: Constants in Rules

#5 Post by TD-er » 28 Nov 2023, 22:19

Burberius wrote: 28 Nov 2023, 18:40 Is there a possibility to get the name of a value from a dummy controller?
Then I could create a controller apikey and set the key as the value name.
You mean like this: https://espeasy.readthedocs.io/en/lates ... r-eventpar
??

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 29 guests