# Nodered and ewpe-smart-mqtt

**URL:** https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828
**Category:** General
**Created:** [10 July 2020 07:32 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828 "2020-07-10T07:32:45Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [10 July 2020 07:32 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/1 "2020-07-10T07:32:45Z")

</div>

> **[stas-demydiuk/ewpe-smart-mqtt](https://github.com/stas-demydiuk/ewpe-smart-mqtt)**
>
> MQTT bridge for EWPE Smart powered devices. Contribute to stas-demydiuk/ewpe-smart-mqtt development by creating an account on GitHub.

Hi there!

Very noob question, I'm trying to use my air conditioner with MQTT broker in nodered, but have no idea how to configure it to just send a setting.

According to the readme, I need to address a topic, in mqtt out, but have no idea how exactly it needs to look like, if lets say I want to inject a power-on and temp unit together.

Could someone share an example?

I started as it suggested in the readme, so the topic is ewpe-smart in the mqtt broker.

THX!

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [10 July 2020 07:45 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/2 "2020-07-10T07:45:57Z")

</div>

Looks like you first have to determine the device id;

inject node -\> mqtt out (properly configured for your broker)  
in the inject node, set topic to `ewpe-smart/devices/list`

mqtt-in node (select the same broker), set topic to `ewpe-smart/#` -\> debug node

Deploy, click the inject node, watch the debug output, it will show you the device id (i would hope)

To turn it on/set temp:

inject node, set topic to `ewpe-smart/{deviceId}/set`, payload to json `{"Pow": 1, "SetTem": 24}`-\> mqtt out  
change the device id from the initial debug output

eg

 ![Screenshot 2020-07-10 at 09.52.17](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e4200651a8d280cf0df7c3bebb0a09652e7fe99d.jpeg)

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [10 July 2020 08:03 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/3 "2020-07-10T08:03:46Z")

</div>

Thanks for your quick answer, I can not even get devices list...

 ![nrmqtt](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/706ccca465f48714874438967758bd58a1a239c7.png)

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [10 July 2020 08:08 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/4 "2020-07-10T08:08:45Z")

</div>

Most useful tool for mqtt i found is [mqtt explorer](http://mqtt-explorer.com), then you can see what is actually being published on the broker, this makes it also easy to determine what values are available and you can immediately see the device id (if the device is publishing).

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [10 July 2020 10:14 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/5 "2020-07-10T10:14:34Z")

</div>

Finally I was able to tinker it to work with the inject node. Thanks for your help, at the end, didnt need the mqtt explorer!

Last question, I've never used JSON as a function.

I don't want to "inject" the action ("pow":0 etc etc), I would like to use a function node, which will be triggered by something (like daytime, after 22:00, shut off etc).

So the question is how does a JSON look like in a function node so that mqtt understands it the same way?

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [10 July 2020 10:33 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/6 "2020-07-10T10:33:29Z")

</div>

in a function node, something like this:

```auto
topic = 'ewpe-smart/deviceId/set'
return {topic:topic, payload:{"Pow": 1, "SetTem": 24}};

```

mqtt requires the `topic` (if not set in the mqtt node itself)

note that the inject could be helpful for your needs, as it can schedule to inject at a specific time as well

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [10 July 2020 10:56 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/7 "2020-07-10T10:56:06Z")

</div>

Yes, and now the fun thing starts. You can bring in a lot of other nice conditions when to turn on/off and what temperature to set

- house is empty & the home alarm system is armed
- presence detection, you just arrived or left home (most likely overkill)
- vacation mode, you and your family is away for a period
- electricity costs, might be cheaper avoiding peak hours if possible  
etc etc

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [10 July 2020 11:12 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/8 "2020-07-10T11:12:44Z")

</div>

Thank you very much bakman2 🙂

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [10 July 2020 11:13 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/9 "2020-07-10T11:13:55Z")

</div>

Well, I already configured my tv, hue lights, and pc to shut off if i left home, now I only need to add some nodes 🙂 But yeah, its actually fun, and comfortable as fk 😃

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [10 July 2020 14:16 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/10 "2020-07-10T14:16:35Z")

</div>

I'm a bit stuck, I don't know if you can also help me out with this.

I set up a scene, look the following:

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/8/e8a622564a557e8874dc9e4e4d81640c3346c0db.png)

Basically, first part gets current temperature, every 5 minutes, it converts from kelvin to c, than rounds it, and creates a global value, namely TempValue, again, as a global value.

2nd part is looping every 5 minutes, and sets diff strongness of cooling for 3 diff temperatures.

Ofc the problem is, that it literally sets the air conditioner every 5 minutes, making it "BEEP" every 5 minutes.

So I guess the cleverest thing would be, if I could achieve that it only sends MQTT to the air conditioner, **IF** the global value (named TempValue) **changes**.

BTW, every "inject" node at the start of each flow, will be diff, I think I will make the temperature part a !start one, its not that much of calculations, it can start as nodered starts, and just keep going.

In the Air cond. part, I will make join (joao) message recieving flow starters, based on my connection to my wifi with my phone (tasker on android-- \> if im connected, send message to nodered, and it starts the air conditioning flow, thats similar to what I do with my lights).

How could I achieve a flow, that starts ONLY if it got the join (joao) messsage, AND the global value changed?

Thank you guys!

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [10 July 2020 14:56 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/11 "2020-07-10T14:56:26Z")

</div>

well look at the RBE node - it will only send output if the input is a different value.

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [10 July 2020 22:05 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/12 "2020-07-10T22:05:09Z")

</div>

Can i suggest two things here

1. Give your variables memorable names - TempValue - will confuse you no end in about six months !! Maybe something like TargetAirconTemperature or CurrentAirconTemperature etc

2. Read the intro at the top of the forum about how to paste a flow into the system so we can actually see what it is doing (rather than a graphic shot)

3. I would use the RBE node to only trigger on changes to the variable

Craig

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [11 July 2020 09:00 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/13 "2020-07-11T09:00:24Z")

</div>

Thanks for the reply man, but the TempValue is only the value I get from openwathermap, if I will use a temp sensor (which i just might some time), I can name that temperature value TempSensorValue, so it's ok.

I can import the flow no problem.

So once again, I have 3 distinct value ranges I want the AC to react to  
between 21-25, 26-30, 31-35 celsiuses.

I want the flow to continue ONLY if it reaches 21, or 26, or 31, but do NOTHING (dont send mqtt push) if its still within their own respected ranges.

[flowsac.json](https://discourse.nodered.org/uploads/short-url/oPdPs8xfNu682AQrDUzwcZJSh7c.json) (18.5 KB)

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [11 July 2020 09:43 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/14 "2020-07-11T09:43:13Z")

</div>

The RBE node will not help you much in this case. It will send the value even for smallest changes so you will notice no difference. So what I suggest is that you write the filtering in the previous function node you already have in place. Hint: use a javascript switch statement

And then you need to save what "range" you are in so that when the next temperature value arrives, you have something to compare with. If you are still in the same range, don't send a command. Hint: use context to save the range variable

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [11 July 2020 10:43 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/15 "2020-07-11T10:43:38Z")

</div>

I would suggest using the smooth node - and average it over (say 10) readings - this will stop hystersis and should mean you will not be jumping around

So feed the incoming temp into a smooth node, then from there into a switch node - have the switch node test on the ranges you are interested in and send that out to RBE nodes. Have a look at the below

```auto
[{"id":"807888c6.ed5a78","type":"inject","z":"4988251a.07771c","name":"Imaginary Temperature","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":240,"y":80,"wires":[["6cb9b920.48c1f8"]]},{"id":"71e6163e.dd4528","type":"inject","z":"4988251a.07771c","name":"Imaginary Temperature","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":240,"y":180,"wires":[["6cb9b920.48c1f8"]]},{"id":"9285636b.25636","type":"inject","z":"4988251a.07771c","name":"Imaginary Temperature","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":240,"y":120,"wires":[["6cb9b920.48c1f8"]]},{"id":"6cb9b920.48c1f8","type":"smooth","z":"4988251a.07771c","name":"Average Temp","property":"payload","action":"mean","count":"10","round":"0","mult":"single","reduce":false,"x":550,"y":120,"wires":[["4851bcde.92eed4"]]},{"id":"4851bcde.92eed4","type":"switch","z":"4988251a.07771c","name":"test for range","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"21","vt":"num","v2":"25","v2t":"num"},{"t":"btwn","v":"26","vt":"num","v2":"30","v2t":"num"},{"t":"btwn","v":"27","vt":"num","v2":"31","v2t":"num"}],"checkall":"true","repair":false,"outputs":3,"x":800,"y":120,"wires":[["4c35c53a.24312c"],["662581ab.5079b"],["e916ccec.bff"]]},{"id":"4c35c53a.24312c","type":"change","z":"4988251a.07771c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":100,"wires":[["f214e6fa.5dc348"]]},{"id":"662581ab.5079b","type":"change","z":"4988251a.07771c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":160,"wires":[["f214e6fa.5dc348"]]},{"id":"e916ccec.bff","type":"change","z":"4988251a.07771c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":220,"wires":[["f214e6fa.5dc348"]]},{"id":"f214e6fa.5dc348","type":"rbe","z":"4988251a.07771c","name":"send on change","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":1310,"y":140,"wires":[[]]}]

```

Craig

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [11 July 2020 10:59 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/16 "2020-07-11T10:59:07Z")

</div>

Thanks for the suggestion of the smooth node, taking an avarage, but thats no good, not by logical thinking...  
I've set temperature getting to get it every 5 minutes.  
This smooth node gets 10 value in an hour.  
If temperature doesn't change, than it gets lets say, 10 times 27 degrees.  
If it was 27 degrees BEFORE the 10 times, it still sends the mqtt to the ac for **no reason, since the temp didnt change**  
It actually would only delay everything

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [11 July 2020 11:32 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/17 "2020-07-11T11:32:02Z")

</div>

Maybe something like this

```auto
[{"id":"5d5764c0.ddc3ec","type":"inject","z":"846d7832.3348c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":1040,"wires":[["ba5e4729.ec9608"]]},{"id":"ba5e4729.ec9608","type":"random","z":"846d7832.3348c8","name":"","low":"15","high":"40","inte":"true","property":"payload","x":310,"y":1040,"wires":[["24ebfcb.8d90504","c3ed07e8.9a5728"]]},{"id":"24ebfcb.8d90504","type":"switch","z":"846d7832.3348c8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"21","vt":"num"},{"t":"lt","v":"26","vt":"num"},{"t":"lt","v":"31","vt":"num"},{"t":"lt","v":"36","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":5,"x":170,"y":1200,"wires":[["3751ee54.1dabc2"],["9de35c4c.4a0de"],["d1ad55e2.d351d8"],["dcc149b8.2c88b8"],["2e1c1adf.393426"]]},{"id":"c3ed07e8.9a5728","type":"debug","z":"846d7832.3348c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":1040,"wires":[]},{"id":"9de35c4c.4a0de","type":"change","z":"846d7832.3348c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"low","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1160,"wires":[["ef39cce1.39875"]]},{"id":"d1ad55e2.d351d8","type":"change","z":"846d7832.3348c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"medium","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1200,"wires":[["ef39cce1.39875"]]},{"id":"dcc149b8.2c88b8","type":"change","z":"846d7832.3348c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"high","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1240,"wires":[["ef39cce1.39875"]]},{"id":"3751ee54.1dabc2","type":"change","z":"846d7832.3348c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"very low","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1120,"wires":[["ef39cce1.39875"]]},{"id":"2e1c1adf.393426","type":"change","z":"846d7832.3348c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"very high","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1280,"wires":[["ef39cce1.39875"]]},{"id":"ef39cce1.39875","type":"rbe","z":"846d7832.3348c8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":570,"y":1120,"wires":[["6af50dd3.46b394"]]},{"id":"6af50dd3.46b394","type":"debug","z":"846d7832.3348c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":1180,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [11 July 2020 12:54 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/18 "2020-07-11T12:54:13Z")

</div>

Yeah this is what I was thinking about, to group them by the ranges, than the rbe can distinct and stop the flow, if it's not in a different range.  
This is ofc working, but doesn't consider what happens, if I turn on the AC after a long time, and the temp matches the range it was before.

So what I need to do, is create a seperate flow, **without** looping, just a 1time startup loop, which is the same without the rbe, that runs, turns accordingly the ac. But at the same time, when that flow starts, another starts **with the rbe** , and **with the loop**.

This way, it surely starts, then only does the loop with the rbe, and only changes if value is different.

Just in case I will upload this scene of flows, in case others would like to look at it.

I'm controlling it with **Join recieve** for flow starts: It sends "turnon" message from my phone when it connects to home wifi, and "turnoff" when I disconnect from wifi **and** I'm outside of Autolocation Geofence Home, just in case I'm still home, but wifi doesn't work.  
Also, it sends a **Join** message to my phone whenever it changes AC settings (low to high or anything), which triggers a short speaker readout with google voice "AC set to low/medium/high".

---

<div class="post-metadata">

### Author: ![MAaron](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maaron/32/9813_2.png) [@MAaron](https://discourse.nodered.org/u/MAaron)
#### Post date: [11 July 2020 13:42 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/19 "2020-07-11T13:42:26Z")

</div>

[flowacv1.json](https://discourse.nodered.org/uploads/short-url/y05FxldbOFQQogksmKkdfICNdMP.json) (23.1 KB)

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [11 July 2020 22:49 UTC](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828/20 "2020-07-11T22:49:08Z")

</div>

Nope not quite - with the RBE node it would not send anything to the AC because the value being passed to it had not changed - thats why i put the change nodes in there based on the range - but you are correct this is to maintain temperature - not when you first turn on and try to reach a temperature

Craig

[Next page](https://discourse.nodered.org/t/nodered-and-ewpe-smart-mqtt/29828.md?page=2)
