Set Variable on Remote ESPEasy

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Set Variable on Remote ESPEasy

#1 Post by gregoinc » 20 Sep 2020, 23:39

Hello,

I have two ESPEasy devices running on NodeMCU units. The ESP1 device controls an air conditioner via the infrared library, and the other ESP2 controls a fan which blows cool air from the outside (during times when the air conditioner is not required).

ESP1 has a temperature sensor inside and outside that is read through rules and when certain criteria are met the air conditioner is turned on. When the air conditioner is turned on I have a TaskValueSet 2,1,1 which is set (1 for on and 0 for off) which is used in Blynk.

I would like ESP1 to tell ESP2 when the air conditioner is running, so ESP2 knows not to start the fan and blow outside air into the room. Is there a way I might be able to get ESP1 to remotely set a variable on ESP2 using say the Let,1,1 command, so the rules on ESP2 could use that in an OR statement.

I've tried a number of SendTo examples, but haven't found any examples for setting a variable on a remote ESPEasy node. Apology if this is covered elsewhere.

Regards, Grego

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

Re: Set Variable on Remote ESPEasy

#2 Post by TD-er » 21 Sep 2020, 00:57

SendTo is using the ESPEasy p2p controller.
This is not the most intuitive configuration, but it should work just fine when setup right.

See: https://espeasy.readthedocs.io/en/lates ... #c013-page

Just a few things you really should take into account:
- Do set unique unit IDs (not 0, nor 255) for each node
- Set the same UDP port on all nodes (preferrably 8266)
- On older builds, you need to reboot after changing the UDP port. Has been fixed only recently.

Without configuring the ESPEasy p2p controller, you can probably already send out commands to another unit, but I guess it wouldn't hurt also having the controller selected and enabled.

gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Re: Set Variable on Remote ESPEasy

#3 Post by gregoinc » 21 Sep 2020, 01:17

Hi TD-er,

I do have the ESPEasy p2p controller running and it works fine. I am unclear how to use the ESPEasy p2p controller for setting a variable... apology, it is probably due to my lack of knowledge.

So as I said, I have the ESPEasy p2p controller working... so do you have examples of how I might solve my question using it?

Thanks, Grego

gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Re: Set Variable on Remote ESPEasy

#4 Post by gregoinc » 21 Sep 2020, 12:59

Whilst we're on the subject of ESPEasy p2p controller, here's a weird 'bug' I have been trying to fix for some time.

Here is the Devices screen for the Generic - Dummy Device on ESP1 (GregoInc1)
ESP1-Generic.jpg
ESP1-Generic.jpg (18.75 KiB) Viewed 10782 times

And here is the Generic - Dummy Device on ESP2
ESP2-Generic.jpg
ESP2-Generic.jpg (23.06 KiB) Viewed 10782 times
What I have never been able to understand is why they are different? Especially when they come from the same source i.e. ESP1?

So, on ESP1 I use the [counter#status] variable in rules to perform a function... see below.

Code: Select all

On StartHP Do
If [counter#status]=0
 heatpumpir,daikin,1,3,0,24,4,2
 TaskValueSet 4,1,1
EndIf
EndOn
Yet, on ESP2 the variable received from ESP1 mysteriously appears to have it's name changed from [counter#status] to [counter#Dummy] and I cannot work out why?

Thanks again for any help, much appreciated.

Grego

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

Re: Set Variable on Remote ESPEasy

#5 Post by TD-er » 21 Sep 2020, 14:44

There is a bug (a known one) regarding a very specific set of plugins, which does manifest itself also when sharing via p2p.
It is related to the plugins which allow to change the number of output values.
Dummy is one of them, just like Sysinfo and a few more.

When you first pair the tasks via p2p, it does send the configuration like value names, but that doesn't work as expected if you use one of those plugins and never changed the value name.

I never tested the calls to set variables on another node, but I don't see any reason why it should not work.
With sendto, you effectively send a command to another node.
So -in theory- it should work to send the command "let,1,123" to another node.

gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Re: Set Variable on Remote ESPEasy

#6 Post by gregoinc » 22 Sep 2020, 05:37

Hi TD-er,

Thanks for the reply. So if I understand correctly... I should be able to use the following examples to update a variable on ESP2

On ESP1 I would have the following code...

Code: Select all

On UpdateVar
   do
   sendTo 2,let,3,1
endon
Then on ESP2 I should be able to use...

Code: Select all

On Rules#Timer=1 do
      if [var#3]=1
     Event,StartFan
   endif   
endon
I assume I can replace the 'let' code with this...

Code: Select all

http://<ESP2>/control?cmd=let,3,1
Am I on the right track with above?

Thanks, Mark

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

Re: Set Variable on Remote ESPEasy

#7 Post by TD-er » 22 Sep 2020, 11:00

I think it can be done also without the variable, as you can also create your own event and act on it via the rules.
An event can have upto 4 values, which you can access via the %eventvalue1% (I guess the others can be guessed) in the rules block.

This way you have near instant reaction on your event.

gregoinc
Normal user
Posts: 65
Joined: 21 Jan 2019, 06:08
Location: Australia

Re: Set Variable on Remote ESPEasy

#8 Post by gregoinc » 23 Sep 2020, 00:14

Hi TD-er,

I think I understand what you are saying... how does below look?

Code: Select all

On Rules#Timer=1 do
if [%eventvalue3%] = 1
    Event,StartFan
endif
endon
I also want to ensure if the air conditioner is running on ESP1, then the fan relay connected to ESP2 doesn't trigger the fan to start.

So I was looking at a code such as below...

This is the code running on ESP1

Code: Select all

On StartHP Do
If [counter#status]=0   // If the air conditioner is already off start it
 heatpumpir,daikin,1,3,0,24,4,2
 TaskValueSet 4,1,1
 sendTo 2,let,3,1   // Tell ESP2 the air conditioner is running
EndIf
EndOn
This is the code in Rules on ESP2...

Code: Select all

On Rules#Timer=2 do
   timerset,2,30
   if [Temp1#Temperature] >= 25 or [var#3]=1  // If the temperature outside is over 25 degrees Celsius or the air conditioner is running then dont start the fan
   Event,StopFan
   endif 
endon
Thanks, Grego

riker1
Normal user
Posts: 344
Joined: 26 Dec 2017, 18:02

Re: Set Variable on Remote ESPEasy

#9 Post by riker1 » 29 Sep 2020, 12:38

TD-er wrote: 22 Sep 2020, 11:00 I think it can be done also without the variable, as you can also create your own event and act on it via the rules.
An event can have upto 4 values, which you can access via the %eventvalue1% (I guess the others can be guessed) in the rules block.

This way you have near instant reaction on your event.

Hi
did the syntax change here in recent releases?

how to send a value with
this worked but not any more.

Code: Select all

 sendTo 149,event,send_kt=[Dev1#Value1]
thanks for updating

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

Re: Set Variable on Remote ESPEasy

#10 Post by TD-er » 29 Sep 2020, 15:27

You could either try to add quotes to the last parameter of "sendto"

Code: Select all

sendTo,149,"event,send_kt=[Dev1#Value1]"
Or check "Tolerant last parameter" in Tools => Advanced.

If it is due to a change in parameter parsing, then there should be quite a lot of information about it in the logs.

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests