Kerui 433 MHz motion sensor config issue

I have a Kerui motion sensor which is 433 MHz. I publish to home/rtl_433 and the following is displayed after the sensor trips. (several other items publish to this topic)

{"time" : "2019-01-24 00:26:07", "model" : "Kerui Security", "id" : 924442, "cmd" : 10, "state" : "motion"}

Not sure what to do with this info. Probably need a value_template for state: motion or something I suppose. I’ve tried and am stuck on this:

  - platform: mqtt
    name: 'Pantry Motion'
    state_topic: 'home/rtl_433'
    payload_on: 'motion'
    payload_off: ''

Made some progress. Got the binary_sensor to flip to on but now I don’t know how to shut it down. The MQTT dump I posted above is all. Sensor only reports on, not reset or off.

  - platform: mqtt
state_topic: home/rtl_433
name: Pantry Motion
value_template: >
  {% if value_json is defined and value_json.id == 924442 %}
    {{ value_json.state }}
  {% endif %}
payload_on: 'motion'
payload_off: 'standby'

It’s most likely the sensor only sends one signal, so, you need to create a fake off signal using an automation. See my example below. I use this for a number of 433 mhz motion sensors to reset them to off after 1 second, as they detect motion every 6 seconds.

binary_sensor.yaml

- platform: mqtt
  name: "Motion 1"
  qos: 1
  state_topic: "home/433toMQTT"
  payload_on: "2890473"
  payload_off: "2890473off"   #This is a fake 'off' payload that gets sent with an automation
  optimistic: true
  retain: false

automation.yaml

# MOTION SENSOR 1 - OFF TIMER #
- alias: Motion Sensor 1 - Off Timer
  hide_entity: true
  trigger:
    platform: state
    entity_id: binary_sensor.motion_1
    to: 'on'
    for:
      seconds: 1
  action:
    service: mqtt.publish
    data:
      topic: 'home/433toMQTT'
      payload: '2890473off'
      retain: 'true'

Thanks. I have a weird condition where everything rf gets published to home/rtl_433

I can’t quite nail the automation because I’m pretty sure I have to value_template or filter template and I’m not so good at that. This is a binary sensor that shows up and does trip when triggered. Just can’t get the sensor to “reset”

   - platform: mqtt
    qos: 1
    state_topic: home/rtl_433
    name: Pantry Motion
    value_template: >
      {% if value_json is defined and value_json.id == 924442 %}
        {{ value_json.state }}
      {% endif %}
    payload_on: 'motion'
    payload_off: 'motionoff'
    optimistic: true
    retain: false

Automation

automation 21:
  alias: Motion Sensor Off
  hide_entity: false
  trigger:
    platform: state
    entity_id: binary_sensor.pantry_motion
    to: 'on'
    for:
      seconds: 1
  action:
    service: mqtt.publish
    data:
      topic: 'home/rtl_433'
      payload: 'motionoff'
      retain: 'true'

The MQTT server does see the published “motionoff” but I’m certain that my value template can’t find it and I’m stumped.

There seems to now be an

off_delay:

variable for the MQTT Binary Sensor. I have it set up but I’m at work VPN’d into my network and I can’t test it until my daughter wakes up and moves around the house which of course could be HOURS. But I’m hopeful it might work.

It worked. She tripped the sensor and I watched it activate then turn off 5 seconds later. Sweet. I’m going to buy a few more of these sensors.

  - platform: mqtt
    qos: 1
    state_topic: home/rtl_433
    name: Pantry Motion
    value_template: >
      {% if value_json is defined and value_json.id == 924442 %}
        {{ value_json.state }}
      {% endif %}
    payload_on: 'motion'
    off_delay: 5
    optimistic: true
    retain: false

Hi John,
How you getting on with these pirs, can you recommend them?