[SOLVED] Switch cotrol + openhab

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mihai.icey.ro
Normal user
Posts: 15
Joined: 01 May 2019, 00:24

[SOLVED] Switch cotrol + openhab

#1 Post by mihai.icey.ro » 01 May 2019, 00:39

Hello,
First of all, I wanted to say that I am new in "smart-house" family... I am doing this to learn new things and they are awweesssommee

I managed to make a hardware lamp. It's an esp8266 esp 12 that controls a light. with ESP Easy 120.
I have some problems here.

I managed to make the configurations for the relay. On GPIO4 (lightSwitch) I have the Switch for the lamp and GPIO5(lightState) is the relay, settings are from this video: https://youtu.be/Kp4KJVbOWd0.
The Rule is this one:

Code: Select all

on lightSwitch#Switch do
	if[lightState#Switch]=1
		gpio,5,0
	else
		gpio,5,1
	endif
endon

If I push the button the light goes off, if I push the button again...it doesn't come back.. I don't know what to do in this case.

The second thing, how can I add a digital button to my openhab sitemap?

I google it both things but I don't know how to really search for them...

Thank you

P.S. the relay it's like the one on the picture attached
Attachments
modul-releu-1-canal.jpg
modul-releu-1-canal.jpg (41.11 KiB) Viewed 2841 times
Last edited by mihai.icey.ro on 08 May 2019, 18:47, edited 1 time in total.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Switch cotrol + openhab

#2 Post by pw444 » 08 May 2019, 16:46

ESP8266 works with 3.3V and the if the relay works with 5V, you need a resistor divider.


Code: Select all

ESP8266 ESP01 - light switch

Define device one as Switch Input, Push Button Active Low, pullup on, GPIO 0. Name it pb01. Name the value #1 as value.
by hardware - gpio-2 - output high - for relay  - gpio-2 low triggers relay
              gpio-0 - input

rules

// pb01   - gpio 0 - D5
// output - gpio 2 - D3
// boots off

On System#Boot do
// GPIO,2,0
endon

on pb01#value do
   gpiotoggle,2
endon

on pb01_on do
  GPIO,2,0
endon

on pb01_off do
  GPIO,2,1
endon

on pb01sw do
  gpiotoggle,2  
endon
this works for me.

mihai.icey.ro
Normal user
Posts: 15
Joined: 01 May 2019, 00:24

Re: Switch cotrol + openhab

#3 Post by mihai.icey.ro » 08 May 2019, 18:46

Sorry, i forgot to close this topic.

I used an NPN Transistor (NPN 2N3904) for controlling the relay, and I used these schematic.

Image

Thank you :)

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests