now i need help how to use with MQTT lots of people talk about it but dont see any proper tutorial for beginner.
so if any body configure please help me how to use signal and send some kind of alert .
Hi
Thanks for Tutorial i already install MQTT and test its ok and working
,as i can see in cloud base system we have option to create topic ,how we do local with MQTT and how to pass data to Mqtt.
please explain
thanks
so default state of door sensor OFF ,when some one open door then state change by receiving code from GPIO 27 .
now what i want i want to send rf key to MQTT topic so i can call in binary sensor.
so that how i plan .
if you understand well please let me know how to do ?
thanks
#!/usr/bin/env python3
import argparse
import signal
import sys
import time
import logging
import paho.mqtt.publish as publish
auth = {
'username':"admin",
'password':"Qazxsw2@"
}
from rpi_rf import RFDevice
rfdevice = None
# pylint: disable=unused-argument
def exithandler(signal, frame):
rfdevice.cleanup()
sys.exit(0)
logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )
parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=27,
help="GPIO pin (Default: 27)")
args = parser.parse_args()
signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
logging.info("Listening for codes on GPIO " + str(args.gpio))
i=0
while True:
if rfdevice.rx_code_timestamp != timestamp:
timestamp = rfdevice.rx_code_timestamp
if str(rfdevice.rx_code) == '9848953':
i = i+1
logging.info("Detect code " + str(rfdevice.rx_code) + " i=" + str(i))
if i == 10:
publish.single("hass/sensor/door_sensor_1","ON",hostname="localhost", auth=auth)
i = 0
time.sleep(60)
time.sleep(0.01)
rfdevice.cleanup()
i find above script i think same as i want but problem with script below is error
import paho.mqtt.publish as publish
ImportError: No module named ‘paho’
can u let me knw whats module name
HI
so far solve this issue as well get code and receive in MQTT ,soo update next step and i have one RF siren so i want to send him command as well any body done send command please mention how to do .
update here with yaml setting please .
thanks for nice forum and people who always here
please confirm is it ok now next want to take action on door open from mqtt i am getting state ON
like below
publish.single(“hass/sensor/door_sensor_1”,“ON”,hostname=“localhost”, auth=auth)
below is my automation file
- alias: Door Opened night time
trigger:
platform: state
entity_id: binary_sensor.Door_Opened_1
from: 'off'
to: 'on'
condition:
- condition: time
after: '19:00:00'
before: '5:00:00'
action:
service: switch.turn_off
entity_id: switch.vision_zl7432_inwall_switch_dual_relay_switch_3_0_3
so above is my yaml setting but action not work how every i test MQTT revive code
Client mosqsub/2179-hassbian sending CONNECT
Client mosqsub/2179-hassbian received CONNACK
Client mosqsub/2179-hassbian sending SUBSCRIBE (Mid: 1, Topic: hass/sensor/door_sensor_1, QoS: 0)
Client mosqsub/2179-hassbian received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/2179-hassbian received PUBLISH (d0, q0, r0, m0, 'hass/sensor/door_sensor_1', ... (2 bytes))
ON
Hi
ok i find problem problem is state sensor.door_opened_1=unknown
so i i set in automation
from: ‘unknown’
to: ‘on’
then it work first time but now later state changed to on .
so my question how to set first time default state then change back to orignal state after few mins.
any body expert ?
did you get it working. I am also stuck at this stage. Already installed paho but same error
pi@rasp:~ $ sudo python3 script_mqtt.py
Traceback (most recent call last):
File "script_mqtt.py", line 8, in <module>
import paho.mqtt.publish as publish
ImportError: No module named 'paho'
Hi
yes its working use below command to paho
pip install paho-mqtt
only problem still not solved that is unknown sensor state so i have done initial state of sensor Closed by default and when detect sensor i show in open and after few second and reset it close.
if u got any other idea share with me.
thanks