Help with: Door Bell, using: RF bridge OMG + RF Button + MQTT + HA

OK here goes, Hi I am a complete newbie at this, I apologise in advance for anything you may think i’m being a tit for not understanding, please break things down so i understand and if referencing to files etc. please say where i’ll locate these said files etc.

I have a windows 7 dedicated server
It has Python 3.7.4 (latest at writing of this)
I have installed HA and running the UI as we speak.

I have an independant MQTT broker (mosquitto) running on same server pc and it is working fine as I have MQTT.fx on a client PC able to remote into it.

I have a sonoff RF bridge flashed with OpenMQTTGateway which is working flawlessly as it is currently reading an RF 433Mhz button keyfob. And it is configured to log to the MQTT mosquitto server.

When I press the keyfob button the mosquitto server gives this reading:

home/OpenMQTTGateway/SRFBtoMQTT/Raw
2BA2012204104BDAB2
home/OpenMQTTGateway/SRFBtoMQTT
4971186
home/OpenMQTTGateway/SRFBtoMQTT/Tsyn
1117
home/OpenMQTTGateway/SRFBtoMQTT/Thigh
290
home/OpenMQTTGateway/SRFBtoMQTT/Tlow
1040

Using this info and a lot of tutorials i have compiled (please correct/re-write if i have made mistakes or you think it can be done better, as im only new to this) in note pad these following entries:

binary_sensor:
    - platform: mqtt
      state_topic: "home/OpenMQTTGateway/SRFBtoMQTT"
      name: 'Door Bell'
      value_template: '{{value_json.RfReceived.Data}}'
      payload_on: '4971186'
      payload_off: '4971186off'
      device_class: door
      optimistic: false
      qos: 1
      retain: false
automations:
alias: Reset RF Button State
hide_entity: true
initial_state: 'on'
trigger:
 platform: state
    entity_id: binary_sensor.Door_Bell
    to: 'on'
    for:
      seconds: 3
  action:
  - service: mqtt.publish
    data:
      topic: home/OpenMQTTGateway/SRFBtoMQTT
      payload: '4971186off'

- alias: 'Door Bell'
    hide_entity: true
    trigger:
    - platform: state
      entity_id: binary_sensor.Door_Bell
      from: 'off'
      to: 'on'
    action:
    - service: tts.google_say
      data:
        entity_id: media_player.whole_house
        message: "There is someone at the front door, please answer the door."

In Home Assistant I have added the chromecast addon and it has indeed found my entire house of google speakers and casts. I have a “Whole House” group which has all linked speakers to it.

I have used the UI to test and send a TTS message and it works to the whole group perfectly.

NOW, here is my troubles. I haven’t a clue where to add the above entries, I “thought” i could add them to the %appdata% windows folder “.homeassistant” (C:\Users\Server\AppData\Roaming.homeassistant)

and just add the binary sensor to the configuration.yaml
and the automations to the automation.yaml

On doing so and saving the files, nothing happens. I press the button, no notification happens. No additional item is added to the “home” page of the Home Assistant UI.

I thought I may need to restart and used the configuration->server control->restart
but that ends in tears, because it doesn’t like what i added to the .yaml files…

Im out of ideas for the time being, please please help. I have honestly tried so hard to figure this out and thought i had done quite well considering the limited knowledge lol

Again if the code can be better or theres a better way through the UI then please give detailed input so as for me to follow your instructions perfectly.

Thank you kindly :slight_smile:

Also do need anything installed like an add-on to communicate the HA to MQTT?

can you format you code make easyer for other to read and help

if you change the binary_sensor to a sensoe

- platform: mqtt
state_topic: “home/OpenMQTTGateway/SRFBtoMQTT”
name: ‘Door Bell’
value_template: ‘{{value_json.RfReceived.Data}}’
# payload_on: ‘4971186’
# payload_off: ‘4971186off’
# device_class: door
#optimistic: false
qos: 1
# retain: false   
expire_after: 1    # <

having the expire_after: will set the sensor back to unknown there for you dont have to have a automation to set it off

then

alias: ‘Door Bell’
hide_entity: true
trigger:

platform: state
entity_id: sensor.Door_Bell
to: ‘4971186’
action:
service: tts.google_say
data:
entity_id: media_player.whole_house
message: “There is someone at the front door, please answer the door.”

my thinking and my rules are

if it send a on command and a off command it binary_sensor

if only send 1 code its a sensor

I have a number of these around the house

https://www.ebay.com/itm/1-2-3-Way-433MHz-RF-Wireless-Remote-Control-Transmitter-Smart-Switch-Wall-Panel/233325232770?_trkparms=aid%3D555018%26algo%3DPL.SIM%26ao%3D1%26asc%3D20190212102350%26meid%3D69a49dbddb894055a62a8c97bdbd3994%26pid%3D100012%26rk%3D4%26rkt%3D12%26sd%3D233179974574%26itm%3D233325232770%26pmt%3D1%26noa%3D0%26pg%3D2047675&_trksid=p2047675.c100012.m1985

I have this sensor

  - platform: mqtt
    name: "Last RF"
    state_topic: "tele/RF_Bridge/RESULT"
    value_template: '{{value_json.RfReceived.Data}}'
    expire_after: 1
    qos: 1

and he is the automations

- id: His side Lamp
  alias: His side Lamp
  initial_state: 'on'
  trigger:
  - entity_id: sensor.last_rf
    platform: state
    to: '137854'
  condition: []
  action:
  - data:
      entity_id: light.his_side
    service: light.toggle
#=======================================================================
# 
#=======================================================================
- id: His side Lamp
  alias: His side Lamp
  initial_state: 'on'
  trigger:
  - entity_id: sensor.last_rf
    platform: state
    to: '137852'
  condition: []
  action:
  - data:
      entity_id: light.master_bedroom
    service: light.toggle
#=======================================================================
# 
#=======================================================================
- id: His side Lamp
  alias: His side Lamp
  initial_state: 'on'
  trigger:
  - entity_id: sensor.last_rf
    platform: state
    to: '137851'
  condition: []
  action:
  - data:
      entity_id: light.her_side
    service: light.toggle

see clear as mud

Many thanks, I have edited my first post into preformatted text and taken on board your methods. I will be eager to test this out this afternoon, when im back from work :smiley:

So the sensor part is to still go into the configuration.yaml?

and the second part is to go into the automations.yaml?

Cheers

Cool bro

If i was you I would start break out the configuration file

step 1

var: !include var.yaml
sensor: !include_dir_merge_list sensor
binary_sensor: !include binarysensor.yaml
notify: !include notify.yaml
#group: !include groups.yaml
automation: !include automations.yaml
automation old: !include_dir_merge_list automations
script: !include scripts.yaml
switch: !include switches.yaml
light: !include light.yaml
climate: !include climate.yaml
input_select: !include input_select.yaml
input_number: !include input_number.yaml
input_text: !include input_text.yaml
input_boolean: !include input_boolean.yaml
counter: !include counter.yaml
fan: !include fan.yaml
cover: !include covers.yaml
media_player: !include media_player.yaml
input_datetime: !include input_datetime.yaml
# scene: !include scene.yaml

do this to your config file

with the
sensor: !include_dir_merge_list sensor

this will pull in all file in said folder
image

it even does folder in side folders

image

You are a star! Many thanks sir :smiley:

I will get it all set and let you know, thanks again.

Howdo,
I have added the “step 1” code you gave me, to my configuration.yaml.

I ran the configuration validation in the HA UI and it reported:

“Component error: var - Integration var not found.”

so i have # that var line for time being, so i could carry on…

Then i created all the .yaml files that were in your !include list, as all of them came up with “not found” errors. All was good after that.

I then added a “sensor: !include sensor.yaml” line and made that file to add the following:

platform: mqtt
state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
name: 'Door Bell'
value_template: '{{value_json.RfReceived.Data}}'
qos: 1  
expire_after: 1

It complained about the quotations being incorect to the listed one above, so i changed them to suit and the everything was fine.

After that I then went to add the second part of code to the automations.yaml and I have added this:

alias: 'Door Bell'
hide_entity: true
trigger:
platform: state
entity_id: sensor.Door_Bell
to: 4971186 
action:
service: tts.google_say
data:
entity_id: media_player.whole_house
message: "There is someone at the front door, please answer the door."

This reported an error of:

“Invalid config for [automation]: [platform] is an invalid option for [automation]. Check: automation->platform. (See C:\Users\Server\AppData\Roaming.homeassistant\configuration.yaml, line 17). Please check the docs at https://home-assistant.io/components/automation/

So then i looked at your example and thought i needed an “id” line so saved the automations file as this:

- id: Door Bell
alias: 'Door Bell'
hide_entity: true
trigger:
platform: state
entity_id: sensor.Door_Bell
to: '4971186'
action:
service: tts.google_say
data:
entity_id: media_player.whole_house
message: "There is someone at the front door, please answer the door."

Now the validation report has changed to:

“Error loading C:\Users\Server\AppData\Roaming.homeassistant\configuration.yaml: while parsing a block collection
in “C:\Users\Server\AppData\Roaming.homeassistant\automations.yaml”, line 1, column 1
expected , but found ‘?’
in “C:\Users\Server\AppData\Roaming.homeassistant\automations.yaml”, line 2, column 1”

So before i muck it up even further i was hoping to get you input if possible please?

take the line var: !include var.yaml that for something else a plug in

entity_id should be in lower case

the states page is you friend open it in a sec browser

image

they all in lower case

hay It all leaning

you wont make the same mistake twice

GOOD to see you just jumping in and praying

I haven’t a clue whats wrong now :’(
Let me say what i have done, and if there is anything i have not done correctly,

  • MQTT is installed and running on my server,

  • I have Hass.io installed on a virtual machine on the same server with configurator installed thats it.

  • In intergrations i have google cast services and the MQTT server details (cast works as i can push messages to it via the H.A overview TTS to my whole house, so i know that works), (I know the MQTT server is working because in the HA Developer section -> MQTT I can publish a test message and Whilst my client pc is logged into MQTT.fx on # subscribed. I can see the said published test message).

  • My configurations.yaml:


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

#sensor: !include_dir_merge_list sensor
#var: !include var.yaml
binary_sensor: !include binarysensor.yaml
notify: !include notify.yaml
#group: !include groups.yaml
automation: !include automations.yaml
automation old: !include_dir_merge_list automations
script: !include scripts.yaml
switch: !include switches.yaml
light: !include light.yaml
climate: !include climate.yaml
input_select: !include input_select.yaml
input_number: !include input_number.yaml
input_text: !include input_text.yaml
input_boolean: !include input_boolean.yaml
counter: !include counter.yaml
fan: !include fan.yaml
cover: !include covers.yaml
media_player: !include media_player.yaml
input_datetime: !include input_datetime.yaml
# scene: !include scene.yaml
sensor: !include sensor.yaml
  • My sensor.yaml
platform: mqtt
state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
name: 'doorbell'
value_template: '{{value_json.RfReceived.Data}}'
qos: 1
expire_after: 1
  • My automations.yaml
- id: doorbell
  alias: doorbell
  hide_entity: true
  trigger:
  - entity_id: sensor.doorbell
    platform: state
    to: '4971186'
  action:
    - service: tts.google_say
      entity_id: media_player.whole_house
      data:
        message: 'There is someone at the front door, please answer the door.'
  • I have my sonoff flashed with OMG and connecting to the MQTT broker. When I push the RF button i get:
home/OpenMQTTGateway/SRFBtoMQTT/Raw
2BA2012204104BDAB2

home/OpenMQTTGateway/SRFBtoMQTT
4971186

home/OpenMQTTGateway/SRFBtoMQTT/Tsyn
1117

home/OpenMQTTGateway/SRFBtoMQTT/Thigh
290

home/OpenMQTTGateway/SRFBtoMQTT/Tlow
1040

I have no idea what else to do… shouldn’t it be working? Do i have to do anything with my MQTT broker for the HA to pick-up a certain command? Have I got the yaml files wrong? I haven’t a clue now. I thought everything was good. I have even restarted HA using the built in server control and no errors publish.
I just don’t know what im doing wrong :’(

Your sensor is wrong:

value_template: >-
{% if value_json.value == ‘4971186’ %}
{{‘ON’}}
{% else %}
{{‘OFF’}}

And in automation state to on

thank you kindly for your help

sensor.yaml

platform: mqtt
state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
name: 'doorbell'
value_template: >-
{% if value_json.value == '4971186' %}
{{'ON'}}
{ else }
{{'OFF'}}
qos: 1
expire_after: 1

the automatic code check reports:

missed comma between flow collection entries at line 5, column 2:
    {% if value_json.value == '497118 ... 
     ^

automations.yaml

- id: doorbell
  alias: doorbell
  hide_entity: true
  initial_state: 'on'
  trigger:
  - entity_id: sensor.doorbell
    platform: state
    to: '4971186'
  action:
    - service: tts.google_say
      entity_id: media_player.whole_house
      data:
        message: 'There is someone at the front door, please answer the door.  There is someone at the front door, please answer the door.'

I put in initial state on? was that correct?

:slight_smile: thank you again!

I have been struggling with it too, when I first had my r bridge. This is part of my binary_sensors.yaml :

  - platform: mqtt
    name: doorbell
    state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
    value_template: >- 
      {% if value_json.value == 14163857 %}
        {{'ON'}}
      {% else %}
        {{states('binary_sensor.doorbell') | upper}}
      {% endif %}
    off_delay: 30
    device_class: 'sound'

  - platform: mqtt
    name: firealarm
    state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
    value_template: >- 
      {% if value_json.value == 13666408 %}
        {{'ON'}}
      {% else %}
        {{states('binary_sensor.firealarm') | upper}}
      {% endif %}
    off_delay: 30
    device_class: 'smoke'

  - platform: mqtt
    name: garagedoor
    state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
    value_template: >- 
      {% if value_json.value == 564886 %}
        {{'ON'}}
      {% else %}
        {{states('binary_sensor.garagedoor') | upper}}
      {% endif %}
    off_delay: 30
    device_class: 'garage_door'
    

So in your case it would be:

  - platform: mqtt
    name: doorbell
    state_topic: 'home/OpenMQTTGateway/SRFBtoMQTT'
    value_template: >- 
      {% if value_json.value == 4971186 %}
        {{'ON'}}
      {% else %}
        {{states('binary_sensor.doorbell') | upper}}
      {% endif %}
    off_delay: 1
    qos: 1

and automation :

- id: '1562219853852'
  alias: doorbell
  hide_entity: true
  trigger:
  - entity_id: binary_sensor.doorbell
    from: 'off'
    platform: state
    to: 'on'
  action:
  - service: tts.google_say
     entity_id: media_player.whole_house
     data:
        message: 'There is someone at the front door, please answer the door.  There is someone at the front door, please answer the door.'

Thank you so much for the examples and writing the bit relevant for me :smiley: really kind of you.

These pictures show literally the copy/pasted code, word for word in new/empty .yaml files

binary_sensor

Automations.yaml warning message is:

bad indentation of a mapping entry at line 11, column 15:
         entity_id: media_player.whole_house
                  ^

Any ideas?

I am getting the “doorbell” icon at the top of the overview and i believe its state is on.
The last part of script is not letting it activate TTS to the google speakers :frowning:

A space to much or to little.

Guys, I cannot thank you enough for all your help. It WORKS!!! BUT, im affraid to say it was a mixture of code and shear determination… In the end I could add it from the configuration -> Automation:

It added a single input to the automation.yaml file ONLY. no other .yaml files

so from that automation editor page the code it inputs to the automation.yaml:

- id: '1567803474037'
  alias: doorbell
  trigger:
  - payload: '4971186'
    platform: mqtt
    topic: home/OpenMQTTGateway/SRFBtoMQTT
  condition: []
  action:
  - data:
      entity_id: 'media_player.whole_house'
      message: There is a caller at the front door, please answer the door.
    service: tts.google_translate_say

and thats it! :smiley: it has taken over a month to get this working and I can’t believe it’s done lol

Again to you two, thank you so much for helping :slight_smile:

P.S.

- id: '1567803474037'
  alias: doorbell
  trigger:
  - payload: '4971186'
    platform: mqtt
    topic: home/OpenMQTTGateway/SRFBtoMQTT
  condition: []
  action:
  - data:
      entity_id: media_player.whole_house
      volume_level: '0.7'
    service: media_player.volume_set
  - data:
      entity_id: media_player.whole_house
      message: There is a caller at the front door, please answer the door.
    service: tts.google_translate_say

Us this code if you want the speakers to auto to 70% volume before announcing.