# Tasmota RF Bridge                    -*-hass-*-

#### WARNING: This is a generated file. Changes will get lost!

script:

  rfbridge_define_sensors:
    mode: single
    sequence:
      - data:
          payload: |
            {
               "availability" : [
                  {
                     "payload_available" : "Online",
                     "payload_not_available" : "Offline",
                     "topic" : "~/LWT"
                  }
               ],
               "device" : {
                  "identifiers" : [
                     "Tasm01"
                  ],
                  "manufacturer" : "Tasmota",
                  "model" : "NodeMCU",
                  "name" : "RfBridge",
                  "sw_version" : "12.2.0"
               },
               "json_attributes_topic" : "~/RESULT",
               "name" : "RfBridge Signal",
               "state_topic" : "~/RESULT",
               "unique_id" : "rfbridge_signal",
               "value_template" : {% raw %}"{{ value_json.RfReceived.Data }}"{% endraw %},
               "~" : "tele/tasm01"
            }
          retain: 0
          topic: homeassistant/sensor/rfbridge/signal/config
        service: mqtt.publish
      - data:
          payload: |
            {
               "availability" : [
                  {
                     "payload_available" : "Online",
                     "payload_not_available" : "Offline",
                     "topic" : "~/LWT"
                  }
               ],
               "device" : {
                  "identifiers" : [
                     "Tasm01"
                  ],
                  "manufacturer" : "Tasmota",
                  "model" : "NodeMCU",
                  "name" : "RfBridge",
                  "sw_version" : "12.2.0"
               },
               "device_class" : "duration",
               "icon" : "mdi:clock-outline",
               "name" : "RfBridge Uptime",
               "state_topic" : "~/STATE",
               "unique_id" : "rfbridge_uptime",
               "unit_of_measurement" : "s",
               "value_template" : {% raw %}"{{ value_json.UptimeSec }}"{% endraw %},
               "~" : "tele/tasm01"
            }
          retain: 0
          topic: homeassistant/sensor/rfbridge/uptime/config
        service: mqtt.publish
      - data:
          payload: |
            {
               "availability" : [
                  {
                     "payload_available" : "Online",
                     "payload_not_available" : "Offline",
                     "topic" : "~/LWT"
                  }
               ],
               "device" : {
                  "identifiers" : [
                     "Tasm01"
                  ],
                  "manufacturer" : "Tasmota",
                  "model" : "NodeMCU",
                  "name" : "RfBridge",
                  "sw_version" : "12.2.0"
               },
               "name" : "RfBridge MqttCount",
               "state_topic" : "~/STATE",
               "unique_id" : "rfbridge_mqttcount",
               "value_template" : {% raw %}"{{ value_json.MqttCount }}"{% endraw %},
               "~" : "tele/tasm01"
            }
          retain: 0
          topic: homeassistant/sensor/rfbridge/mqttcount/config
        service: mqtt.publish
      - data:
          payload: |
            {
               "availability" : [
                  {
                     "payload_available" : "Online",
                     "payload_not_available" : "Offline",
                     "topic" : "~/LWT"
                  }
               ],
               "device" : {
                  "identifiers" : [
                     "Tasm01"
                  ],
                  "manufacturer" : "Tasmota",
                  "model" : "NodeMCU",
                  "name" : "RfBridge",
                  "sw_version" : "12.2.0"
               },
               "name" : "RfBridge WifiCount",
               "state_topic" : "~/STATE",
               "unique_id" : "rfbridge_wificount",
               "value_template" : {% raw %}"{{ value_json.Wifi.LinkCount }}"{% endraw %},
               "~" : "tele/tasm01"
            }
          retain: 0
          topic: homeassistant/sensor/rfbridge/wificount/config
        service: mqtt.publish


  rfbridge_button_0_pressed:

    mode: queued
    sequence:
      - service: script.smotty_notify
        data:
          message: Button 0 pressed
      - service: telegram_bot.send_message
        data:
          message: Button 0 pressed

  rfbridge_button_a_pressed:

    mode: queued
    sequence:
      - service: telegram_bot.send_message
        data:
          message: Button A pressed

  rfbridge_button_b_pressed:

    mode: queued
    sequence:
      - service: telegram_bot.send_message
        data:
          message: Button B pressed

  rfbridge_button_c_pressed:

    mode: queued
    sequence:
      - service: telegram_bot.send_message
        data:
          message: Button C pressed

  rfbridge_button_d_pressed:

    mode: queued
    sequence:
      - service: telegram_bot.send_message
        data:
          message: Button D pressed

  rfbridge_button_2_pressed:

    mode: queued
    sequence:
      - service: telegram_bot.send_message
        data:
          message: Button 2 pressed

  rfbridge_doorbell_pressed:

    mode: queued
    sequence:
      - service: notify.mobile_app_myphone
        data:
          message: TTS
          data:
            tts_text: Someone at the door
            priority: high
            ttl: 0
            media_stream: "alarm_stream_max"
            importance: high
      - service: telegram_bot.send_message
        data:
          message: Doorbell pressed

homeassistant:
  customize:
    sensor.rfbridge_uptime:
      friendly_name: Uptime (s)



automation:

  # Setup autodiscovery for the sensors.
  - alias: Trigger RfBridge device sensors definitions
    id: Automation__Trigger_RfBridge_device_sensors_definitions
    trigger:
      - platform: homeassistant
        event: start
    action:
      - service: script.rfbridge_define_sensors
        data: {}



  - id: Automation__RfBridge_Button_Pressed
    alias: RfBridge Button Pressed
    description: ''
    mode: queued

    trigger:
      - platform: state
        entity_id:
        - sensor.rfbridge_signal
        attribute: Time

    variables:
      button_mapper:
        "0x112233": Button_0
        "0x223311": Button_A
        "0x223322": Button_B
        "0x223333": Button_C
        "0x223344": Button_D
        "0x1122FF": Button_2
        "0xD00D00": Doorbell

    condition: |-
      {{ trigger.to_state.state not in ( "unavailable", "unknown" )
         and
         trigger.from_state.state != "unavailable"
      }}

    action:
      - service: >
          {% if button_mapper[trigger.to_state.state] %}
          script.rfbridge_{{ button_mapper[trigger.to_state.state]|lower }}_pressed
          {% else %}
          telegram_bot.send_message
          {% endif %}
        data:
          message: >
            Button {{ trigger.to_state.state }}
            (atts  {{ state_attr('sensor.rfbridge_signal','RfReceived') }})
            pressed
