Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




4499 posts

Uber Geek

Trusted

#240034 16-Aug-2018 11:16
Send private message

Absolutely loving this combo of ESP Easy and Node-RED. Have made a whole bunch of little modules, for activating relays and recently just grabbed a bunch of Sonoff's for controlling lighting circuits.

 

So the set up is a Sonoff Basic switch, loaded with ESP Easy, and then the exisiting light switch wired in to GPIO 14 so people can still use the switch.

 

There is an internal "rule" in the sonoff that says, when the state of GPIO 14 changes, toggle the relay output. Looks like this:
[code]
on ext_sw#Switch do
if [relay#state]=0
event switchon
else
event switchoff
endif
endon

 

on switchon do
gpio 12,1
endon

 

on switchoff do
gpio 12,0
endon
[/code]

 

But I've come across one really annoying thing. When the Sonoff reboots, it triggers this rule, and toggles the relay meaning that lighting circuit will turn on for a few seconds and turn off again.

 

This makes sense as the switch state has "changed" so the rule should trigger, but still really annoying. But I am seriously struggling to do this sort of basic logic. I've made sure the boot state of GPIO 12 is low, but it still gets toggled because the switch event runs at boot. There is an event called 'System#Boot' you can run rules on, so I've tried simple delay and timer rules, but they don't do anything either. So my thought process is rather than do this on the Sonoff, do it in Node-red.

 

I'm pretty sure I need to write a function node, but everything I have tried just doesn't work. Hoping someone on here knows their Javascript and can point in the right direction.

 

There are two MQTT topics:
/sonoff20/relay/state <--- reports is the relay on (1) or off (0)
/sonoff20/ext_sw_Switch <--- reports everytime the switch state changes to either 1 or 0

 

So in Node-RED I need a flow that says "on 'switch event', if "relay state" is 0, change it to 1, or if relay state is 1, change it to 0"

 

My thought process says I need to store "relay state" in some sort of a persistent variable, and then just toggle that between 1 & 0 on each switch event. It doesn't matter if the switch output is 1 or 0, we just want the rule to run each time it changes (input in to the function node can be via a 'report by exception' node to achieve this).


Create new topic
265 posts

Ultimate Geek


  #2075349 18-Aug-2018 16:20
Send private message

Use a Switch node to store the relay state value to a flow variable.

 

Here is how I store the last date/time the washing machine door was opened:

 

 

 

 

On 'switch event', use another Switch node to check the value of the stored flow variable.

 

Here is how I checked if the washing machine door was  opened by comparing current and previous opened times:

 

 

 

 

 


Create new topic



Twitter and LinkedIn »



Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

OPPO Find X2 Lite brings flagship features to mid-range 5G smartphone
Posted 29-May-2020 12:52


Sony introduces the digital camera ZV-1 for content creators
Posted 27-May-2020 12:47


Samsung Announces 2020 QLED TV Range
Posted 20-May-2020 16:29


D-Link A/NZ launches AI-Powered body temperature measuring system
Posted 20-May-2020 16:22


NortonLifeLock Online Banking Protection now available for New Zealand banks
Posted 20-May-2020 16:14


SD Express delivers new gigabyte speeds for SD memory cards
Posted 20-May-2020 15:00


D-Link A/NZ launches Nuclias cloud managed network solution hosted in Australia
Posted 11-May-2020 17:53


Logitech introduces new video streaming solution for home studios
Posted 11-May-2020 17:48


Next generation Volvo cars to be powered by Luminar LiDAR technology
Posted 7-May-2020 13:56


D-Link A/NZ launches Wi-Fi Certified EasyMesh system
Posted 7-May-2020 13:51


Spark teams up with Microsoft to bring Xbox All Access to New Zealand
Posted 7-May-2020 13:01


Microsoft plans to establish its first datacenter region in New Zealand
Posted 6-May-2020 11:35


Genesis School-gen has joined forces with Mind Lab Kids
Posted 1-May-2020 12:53


Malwarebytes expands into privacy with fast, frictionless VPN
Posted 30-Apr-2020 16:06


Kordia to donate TV airtime on Channel 200 to community groups
Posted 30-Apr-2020 16:00



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.


Support Geekzone »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.