arendst / Sonoff-MQTT-OTA-Arduino

Provide ESP8266 based itead Sonoff with Web, MQTT and OTA firmware using Arduino IDE - Now EOL
618 stars 197 forks source link

GPIO14 MQTT Status only no relay control #197

Closed stoehrmark closed 7 years ago

stoehrmark commented 7 years ago

I know you have answered this before but I cannot figure it out. I want to use GPIO14 with a switch. I want to know if the switch is open or closed (1 … 0). I do not want the switch to control the relay on GPIO12 just show its status to MQTT. Below is the circuit I am using. I have a DHT22 connected to GPIO3 (this is working fine). I have commented out the part in the script that won’t allow 2 thing on GPIO14 (see below). When i use the code as is the relay turns on and off. Not what i want.

How do I do the following that you posted --> Define a ButtonTopic and you'll receive a cmnd/<ButtonTopic>/POWER message when USE_WALL_SWITCH is enabled.

Thanks for all the work on this project.

/-------------------------------------------------------------------------------------------\

I have commented out the following because I use GPIO3 for the DHT /*

if ((defined(ST_DSB) && defined(ST_DHT)) || (defined(ST_DSB) && defined(USE_WALL_SWITCH)) || (defined(ST_DHT) && defined(USE_WALL_SWITCH)))

if ((DSB_PIN == DHT_PIN) || (DSB_PIN == SWITCH_PIN) || (DHT_PIN == SWITCH_PIN))

error "Select either SEND_TELEMETRY_DS18B20 or SEND_TELEMETRY_DHT or USE_WALL_SWITCH or use different GPIOs"

endif

endif

*/

untitled sketch_bb

img_3407

alphalove commented 7 years ago

Hello, Believe this is possible, have a look at https://github.com/arendst/Sonoff-MQTT-OTA-Arduino/issues/141

Cheers,

alex

arendst commented 7 years ago

Execute command ButtonTopic test1.

When you now flip the switch a message should be send by sonoff like cmnd/test1/POWER ON.

stoehrmark commented 7 years ago

OK so in console on the web interface i entered ButtonTopic garagedoor . I now get a response of change from the Sonoff

Switch ON --> 09:04:29 MQTT: cmnd/garagedoor/POWER = ON Switch OFF --> 09:04:30 MQTT: cmnd/garagedoor/POWER = ON

2 Questions.

  1. The Sonoff on board button no longer works as before. It is now assigned to the ButtonTopic (probably this is what you expect). Can this be a separate thing? The on board button GPIO0 working as normal and a switch attached to GPIO14 assigned to the ButtonTopic independent of each other.

  2. The response from ButtonTopic is only ON. Is there a way to get ON and OFF status e.g. Switch ON --> 09:04:29 MQTT: cmnd/garagedoor/POWER = ON Switch OFF --> 09:04:30 MQTT: cmnd/garagedoor/POWER = OFF

arendst commented 7 years ago

Your findings are correct. I'll investigate in the future.

stoehrmark commented 7 years ago

Thanks for your work on this. It seems that a few people have been asking for a similar feature. Can't wait until you have time to add it in. All the best and thank you again.

arendst commented 7 years ago

Altough solved in version 3.1.14 just released where it would send a TOGGLE. See #206 for explanation.

Your option 1 has not yet been implemented. Your option 2 has always worked when a switch is connected to gpio14. It's action is different from the button on gpio0.

arendst commented 7 years ago

See #206.