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.




4172 posts

Uber Geek


# 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
258 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 »

Streaming service Acorn TV launches in New Zealand with selection with British shows
Posted 18-Sep-2019 08:55


Bitcoin.com announces partnership with smartphone manufacturer HTC
Posted 16-Sep-2019 21:30


Finalists Announced for Microsoft NZ Partner Awards
Posted 16-Sep-2019 19:37


OPPO Showcases New CameraX Capabilities at Google Developer Days China 2019
Posted 15-Sep-2019 12:42


New Zealand PC Market returns to growth
Posted 15-Sep-2019 12:24


Home sensor charity director speaks about the preventable death which drives her to push for healthy homes
Posted 11-Sep-2019 08:46


Te ao Maori Minecraft world set to inspire Kiwi students
Posted 11-Sep-2019 08:43


Research reveals The Power of Games in New Zealand
Posted 11-Sep-2019 08:40


Ring Door View Cam now available in New Zealand
Posted 11-Sep-2019 08:38


Vodafone NZ to create X Squad
Posted 10-Sep-2019 10:25


Huawei nova 5T to be available 20th September
Posted 5-Sep-2019 11:55


Kogan.com launches prepay challenger brand Kogan Mobile in New Zealand
Posted 3-Sep-2019 11:42


Pagan Online available now
Posted 27-Aug-2019 20:22


Starship hopes new app will help combat antibiotic resistance challenges
Posted 27-Aug-2019 19:43


Intel expands 10th Gen Intel Core Mobile processor family
Posted 23-Aug-2019 10:22



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.