All wright, been reading and fiddling for 3 days on how to use a normal switch to flip an input pin high and low and read the result on Node-Red via mqtt.
The goal is to monitor the state of switches in the field like i do with arduinos or pi's.
Hardware: gpio 12 as input
device: switch input, normal switch, input pullup inverse logic,
rules:
on sw1#switch=1 do
publish /wemos1/gpio/12,1
endon
on sw1#switch=0 do
publish /wemos1/gpio/12,0
endon
switch leg1------>grnd
leg2----->1k resistor---->3.3
leg2 ---- >gpio0
So when i close the switch i'm receiving a 1 in node red, so fine, but when i open it it toggles between 0 and 1 at the rate of the debounce field in the device menu.
This has to do with the rule set because without rule it behave ok in the log screen. I tried many examples and i can't make it work otherwise.
What i'm i doing wrong?
Thanks for your help, wonderfull project.
reading an input switch over mqtt
Moderators: grovkillen, Stuntteam, TD-er
reading an input switch over mqtt
Last edited by jupiter8 on 06 Feb 2019, 01:08, edited 1 time in total.
Re: reading an input switch over mqtt
what did you set the switch type to?
Re: reading an input switch over mqtt
Normal switch.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: reading an input switch over mqtt
Code: Select all
on sw1#switch do
Event,PublishState=[sw1#switch]
EndOn
On PublishState Do
Publish,/wemos/gpio/12,%eventvalue%
EndOn
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you

ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you



Re: reading an input switch over mqtt
Thanks, but still no go, tried with a simple push button pin 12 to ground and on release still bouncing from 0 to 1 each 200 millisec.
Using mega-20190202
Using mega-20190202
Re: reading an input switch over mqtt
If you just want to send to mqtt the state of the switch, you can just tick the send to controller box, presuming you have set the mqtt broker correctly in controller, it will sent the state of the switch every time it changes state (interval set to 0) without the need to use any rules.
I had it working on a nodemcuv3, using gpio0 (flash) button which is on the board for convenience. In node red, I use simple flow to monitor the mqtt topic with just a mqtt node and the debug, the debug node shows the switch state correctly with no debounce issues. You can of course add a function node in NR to do what you want on the state change.
Another thing to try maybe is an external pull up resistor and not inverse.
I had it working on a nodemcuv3, using gpio0 (flash) button which is on the board for convenience. In node red, I use simple flow to monitor the mqtt topic with just a mqtt node and the debug, the debug node shows the switch state correctly with no debounce issues. You can of course add a function node in NR to do what you want on the state change.
Another thing to try maybe is an external pull up resistor and not inverse.
Re: reading an input switch over mqtt
Well, thanks for this.
I had this whole topic naming thing mixed up.
I was subscribed on: /wemos2/gpio/12 like i did for a relay...
so i just subscribed on: /wemos2/# to see what's going on and discovered that the topic is in fact: /wemos2/sw1/Switch
now works perfectely.
I had this whole topic naming thing mixed up.

so i just subscribed on: /wemos2/# to see what's going on and discovered that the topic is in fact: /wemos2/sw1/Switch
now works perfectely.
Who is online
Users browsing this forum: Google [Bot] and 21 guests