433 RF Door Sensor Help needed

HI
i am new to HA just see some tutorial but still confuse about 433 RF integration ,so far hardware wart i done and get door sensor open signal thats below
> 2017-03-16 23:04:14 - [INFO] rfrx: Listening for codes on GPIO 27
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 340, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 340, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 343, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 340, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 340, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 340, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 340, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 340, protocol 1]
> 2017-03-16 23:04:27 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]
> 2017-03-16 23:04:28 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]
> 2017-03-16 23:04:28 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]
> 2017-03-16 23:04:28 - [INFO] rfrx: 9848953 [pulselength 343, protocol 1]
> 2017-03-16 23:04:28 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]
> 2017-03-16 23:04:28 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]
> 2017-03-16 23:04:28 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]
> 2017-03-16 23:04:28 - [INFO] rfrx: 9848953 [pulselength 341, protocol 1]

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 .

Both of these are useful. IIRC, one also gives you the steps to test that MQTT is working.

mosquitto_sub -d -u username -P password -t dev/test
mosquitto_pub -d -u username -P password -t dev/test -m “Hello world”

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

There are a bunch of MQTT components. Pick the one specific to what you’re trying to do.

ok here what i want to do i want to use MQTT binary sensor - Home Assistant

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 :slight_smile:

Work on your YAML. Post it when you get stuck. There are lots of examples in this forum and on the component pages.

Hi
continuw with door sensor now i setup sesonr.yaml

  • platform: mqtt
    state_topic: “hass/sensor/door_sensor_1”
    name: “Door_Opened_1”
    qos: 0
    payload_on: “ON”
    payload_off: “OFF”
    sensor_class: opening

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

as well below i got HA what it received

17-03-21 23:23:27 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state sensor.door_opened_1=unknown; friendly_name=Door_Opened_1 @ 2017-03-21T23:22:11.430865+05:30>, new_state=<state sensor.door_opened_1=ON; friendly_name=Door_Opened_1 @ 2017-03-21T23:23:27.383682+05:30>, entity_id=sensor.door_opened_1>

please let me know where is wrong setting why action not work

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