PIR: SONOFF CT60 - expire_after default & substring?

Hi,

started with homeAssist 3 days ago - amazing capabilities, I really think i like it. A lot of sensors, camera, AVR, SONOFF Pow - just integrated quite easy.

Obviously just started with the yaml configuration and would need a little push in the right direction for this one:

  • I have a SONOFF CT60 PIR (433Mhz) that reports to MQTT via SONOFF RF Bridge (Espurna)
  • Motion is triggered, but not cleared. I use expire_after and get ‘UNDEFINED’ on clear. Can i get a defined value (e.g. 0) on expire_after?
  • The MQTT messages look like below - its the same sensor, i need to cut off the first 8 characters for proper recognition :frowning: Alternativly a match on the last chars would work, too.
sonoff/rfbridge/rfin : 30DE01A404C4D263CE
sonoff/rfbridge/rfin : 30F201A404C4D263CE

Sensor:Undefined
Sensor:Motion detected

The following section is what I use so far:

  • platform: mqtt
    name: “rfbridge_rfin”
    payload_on: “30FC01A404C4D263CE”
    state_topic: “sonoff/rfbridge/rfin”
    #value_template: ???
    device_class: motion
    expire_after: 3

Thanks :slight_smile:

I think you need to log into your sonoff and change (or determine) the payload_off:

It appears you can do it on the RF bridge

From the ESPurna web UI you can manage the stored codes. By default you have 6 ON/OFF pairs but you can change that in the configuration files, anyway it way more than the 4 codes the official app can handle. Once “learnt”, you can use them from the main status page, like you would with any other switch.

Interessting reply - didn’t consider to fix it in the Bridge. However, after thinking about it for a while, I still think I need to fix it in the HomeAssistant configuration.
I have Brennenstuhl Power Switches that work as you describe in the Bridge & HomeAssistant.

Brennenstuhl Power Switch

However, the difference for the PIR is:

  • Espurna attaches a random ?6? chars in front of the PIR idea (compare 30DE01A404C4D263CE with 30F201A404C4D263CE). For different PIRs I’d like to substr that to C4D263CE to know if its LIVINGROOM or FLOOR
  • Even the bridge would only get the ‘Alert’ and not a ‘Alert reset’. Maybe the undefined that i have right now is good enough for logic, but for the charting reset to ‘0’ on expire would be nicer.

Regards,
Alex

I use the community 433toMQTT ESP8266 set up, and need to use this automation to reset all my motion sensors to off or no motion as they only send a single detected message. You could adapt this automation to send Home Assistant to off command.

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

Cool - will try that one.
Is there a way to rework the received entry in value_template, e.g. substring or match & replace?

You probably could, I haven’t tried to do that though. Let me know if you have success with that.

“You probably could…”

The docu seems to indicate I could - however in reality I’m doing it wrong, i guess. I also read about ‘filter’ but don’t really find examples on how to apply those…

value_template: ‘{{ regex_replace(value, find=“63CE”, replace=“AS”, ignorecase=False) }}’

2018-04-15 11:00:57 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.mqtt]: invalid template (TemplateSyntaxError: Encountered unknown tag ‘regex_replace’.) for dictionary value @ data[‘value_template’]. Got ‘{% regex_replace(value, find=“63CE”, replace=“AS”, ignorecase=False) %}’. (See ?, line ?). Please check the docs at MQTT Sensor - Home Assistant

Got it to work - thanks!

sensor:

  • platform: mqtt
    name: “rfbridge_rfin”
    payload_on: “0”
    state_topic: “sonoff/rfbridge/rfin”
    value_template: ‘{{ value[10:] }}’
    #313801A404C4D263CE → C4D263CE
    device_class: motion

automation:

  • alias: ‘Motion Sensor 1 - Off Timer’
    trigger:
    platform: state
    entity_id: sensor.rfbridge_rfin
    to: ‘C4D263CE’
    for:
    seconds: 2
    action:
    service: mqtt.publish
    data:
    topic: ‘sonoff/rfbridge/rfin’
    payload: ‘0’
    retain: ‘true’
1 Like