GlobalSync, API & MQTT

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
gandalf
New user
Posts: 5
Joined: 26 Jul 2020, 23:17

GlobalSync, API & MQTT

#1 Post by gandalf » 27 Jul 2020, 07:56

hi guys
I was looking at global Sync. i think it's great
If i understood properly, with globalsync i can access pin of a "remote" device from any node forming the network, right?

In example the node with a temperature probe, could power on the chiller connected to a different node if temperature rise

So, some questions:
1. Any example on how to use this in rules?
2. Can i trigger this via api call? In example talking to node5 to Power on relay2 on node 3
3. Can i do the same via mqtt?
4. Any mqtt global status reporting the state and sensors of all connected nodes?

Tnx

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

Re: GlobalSync, API & MQTT

#2 Post by TD-er » 27 Jul 2020, 10:07

Globalsync has been removed and re-implemented via the ESPEasy p2p protocol.
See for more info the documentation: https://espeasy.readthedocs.io/en/lates ... #c013-page
And if you're still seeing the "Global Sync" option, I suggest to upgrade to a more recent build: https://github.com/letscontrolit/ESPEasy/releases

gandalf
New user
Posts: 5
Joined: 26 Jul 2020, 23:17

Re: GlobalSync, API & MQTT

#3 Post by gandalf » 27 Jul 2020, 10:31

I don't need "global sync". I'm looking for something being able to power on a relay from a temperature read on a different node and something similiar.

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

Re: GlobalSync, API & MQTT

#4 Post by TD-er » 27 Jul 2020, 10:47

Then the ESPEasy p2p I mentioned is a good option to share sensor values among nodes.
You can then add a "virtual task" (lack of a better term) which receives data from another node that actually has the sensor.

This will allow to use the values in rules just as if the sensor was connected to the node itself.

Other options are to send "events" from one node via http to another node (both using rules)
Or you may want to use the MQTT import plugin to retrieve values from whatever source and use those in rules on the node with the relay.

gandalf
New user
Posts: 5
Joined: 26 Jul 2020, 23:17

Re: GlobalSync, API & MQTT

#5 Post by gandalf » 27 Jul 2020, 10:54

Uhm, something automated ? Let's assume I have 20-30 nodes, each one with some sensors and some relays. I also have one remote cloud server (with MQTT).
What I need is:

1) being able to receive, on the cloud server, a full state of the whole network. So I need to know which relay is powered on, which one is powered off, the temperature read by each sensor and so on. A full network state.
2) from this cloud server, better with MQTT (no nat issues and so on), being able to trigger actions, like power on node4.relay2, better without having to subscribe tons of topics (more than one for each node)
3) being able to save some "actions" based on global events (like "IF node3.temp1 <= 26 AND node2.relay1 off THEN node4.relay2 on) on one node. In this way, actions will be exectued even if the cloud connection is lost.

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

Re: GlobalSync, API & MQTT

#6 Post by TD-er » 27 Jul 2020, 12:10

If you need to have it working even when the 'cloud connection' is lost, then I suggest to use the p2p controller.
If you need to "broadcast" the values of a sensor to multiple other nodes, then you can send to the "broadcast" unit number (either 0 or 255, have to look at the code or docs for that)

N.B. The p2p broadcast is not really efficient with lots of nodes.
I guess 10 is about the practical max for the p2p broadcast as it is not really a broadcast but sending the same message to each known node.

Or you can use rules on the sensor nodes to send events to another node including the value or if you can already determine an action to perform to send an event that will trigger an action.
Such events can be sent directly (via the p2p UDP layer) to a node, or you call a http URL to send an event.


Making the "always know the state" from the MQTT broker is a bit tricky.
If a node reconnects, it does not send its current state to the broker.
This way the broker may not show the current state if you also change states via rules or events from other nodes.

gandalf
New user
Posts: 5
Joined: 26 Jul 2020, 23:17

Re: GlobalSync, API & MQTT

#7 Post by gandalf » 27 Jul 2020, 12:55

Do you some some example ? I'm new to this software and currently, not everything is clear to me.

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

Re: GlobalSync, API & MQTT

#8 Post by TD-er » 27 Jul 2020, 16:00

These instructions should help you to share a task to another node: https://espeasy.readthedocs.io/en/lates ... mong-nodes

Make sure to use the same UDP port (Tools => Advanced) on all nodes in your network and also it is very important the nodes have a unique unit number (not being 0 or 255)
Suggested port is UDP port 8266.


For using events in rules, see: https://espeasy.readthedocs.io/en/lates ... g-examples

For sending an event (or data) to another node from rules via p2p, see the command "sendto" https://espeasy.readthedocs.io/en/lates ... nd-publish

Also see this sticky topic on GitHub, to make sure you are familiar with the recent changes regarding wrapping parameters of a command in quotes: https://github.com/letscontrolit/ESPEasy/issues/2724
Not all examples in the documentation may be updated with these changes in mind.

gandalf
New user
Posts: 5
Joined: 26 Jul 2020, 23:17

Re: GlobalSync, API & MQTT

#9 Post by gandalf » 28 Jul 2020, 10:49

Just to be sure if espeasy could do the job.

Let's assume I have to power on a small pump for 1 second (or even 0.5 seconds).
Can I do that, with an rule based on an event or, even better, triggering the 0.5 power on from a different node, when temp read is >= 25 ?

In example:

Code: Select all

  IF 
     node1.sensor2 >= 25 
  THEN 
     power on node3.relay4 for 0.5 seconds
or starting a task after 30 seconds after node boot.

Actually, i'm testing ESPHome that does everything i need, but I have to build and flash a new firmware every time (that's not an issue if they add HTTP OTA updates) but I would like something like node-red flow:
https://jjssoftware.github.io/esp8266-m ... iler-hack/

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

Re: GlobalSync, API & MQTT

#10 Post by TD-er » 28 Jul 2020, 12:19

Sending a single pulse, dan be done using the command longpulse_ms
So this can be done in a rules block triggered by an event.
You can generate an event from the node with the sensor and send this event to another node.
In the rules you can let it act on the measured temperature, or even use the "level" plugin to me a bit more intelligent compared to simply comparing it to a value.

So on the node with the sensor, you set the "level" plugin to a task and let it monitor the temperature sensor task.
This will then trigger an event which you catch in the rules and send out an event to another node.
On the other node, you act on this event from within the rules and send out a longpulse_ms to turn on your pump.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 102 guests