JLindvig

MQTT Sensor Jinja result

Oct 25th, 2020
1,063
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ################################################################################
  2. #        __  _______  ____________   _____                                     #
  3. #       /  |/  / __ \/_  __/_  __/  / ___/___  ____  _________  __________     #
  4. #      / /|_/ / / / / / /   / /_____\__ \/ _ \/ __ \/ ___/ __ \/ ___/ ___/     #
  5. #     / /  / / /_/ / / /   / /_____/__/ /  __/ / / (__  ) /_/ / /  (__  )      #
  6. #    /_/  /_/\___\_\/_/   /_/     /____/\___/_/ /_/____/\____/_/  /____/       #
  7. #                                                             by J-Lindvig     #
  8. ################################################################################
  9. # Created: 25/10/2020                                                          #
  10. ################################################################################
  11. windows_doors:
  12.   group:
  13.     open_sensors:
  14.       name: "Vinduer og døre med åbn sensor"
  15.       icon: mdi:window-open-variant
  16.       all: true
  17.       entities:
  18.        - binary_sensor.havelaage
  19.  
  20.     open_close_sensors:
  21.       name: "Vinduer og døre med åbn/luk sensor"
  22.       icon: mdi:window-closed-variant
  23.       all: true
  24.       entities:
  25.        - binary_sensor.dobbelt_terrassedoer
  26.  
  27.   automation:
  28.     - alias: "RF Bridge Demux"
  29.       mode: parallel
  30.       trigger:
  31.         - platform: mqtt
  32.           topic: "tele/kontor/RESULT"
  33.         - platform: mqtt
  34.           topic: "tele/indgang/RESULT"
  35.         - platform: mqtt
  36.           topic: "tele/pigernes_stue/RESULT"
  37.       action:
  38.         - service: "python_script.rfbridge_demux"
  39.           data:
  40.             payload: "{{ value_json.RfReceived.Data }}"
  41.  
  42.   binary_sensor:
  43.     - platform: mqtt
  44.       name: "Havelåge"
  45.       unique_id: cd71f96a0d0e412bba41e91e3866ee07
  46.       device_class: door
  47.       state_topic: "home/Havelåge"
  48.       off_delay: 15
  49.  
  50.     - platform: mqtt
  51.       name: "Dobbelt_terrassedoer"
  52.       unique_id: 4b03ffb918314900b4b59eed108c1960
  53.       device_class: door
  54.       state_topic: "home/Dobbelt terrassedør"
  55.  
  56.   script:
  57.     reload_mqtt_sensors:
  58.       alias: "Genindlæs MQTT sensorer"
  59.       icon: mdi:reload
  60.       description: "Genindlæs MQTT, Grupper, Templates og Scripts"
  61.       mode: single
  62.       sequence:
  63.         - service: automation.reload
  64.         - service: mqtt.reload
  65.         - service: template.reload
  66.         - service: group.reload
  67.  
  68. ################################################################################
  69. ####                              End of file                               ####
  70. ################################################################################
  71.  
  72.  
  73. sensors = {
  74.   "3C003A": ["Havelåge", "ON", "false"],
  75.   "45400A": ["Dobbelt terrassedør", "ON", "true"],
  76.   "45400E": ["Dobbelt terrassedør", "OFF", "true"]
  77. }
  78. payload = data.get("payload")
  79.  
  80. if payload is not None:
  81.   if payload in sensors.keys():
  82.     service_data = {"topic": "home/{}".format(sensors[payload][0]), "payload":"{}".format(sensors[payload][1]), "qos":0, "retain":"{}".format(sensors[payload][2])}
  83.   else:
  84.    service_data = {"topic":"home/unknown", "payload":"{}".format(payload), "qos":0, "retain":"false"}
  85.     logger.warning("<rfbridge_demux> Received unknown RF command: {}".format(payload))
  86.  hass.services.call("mqtt", "publish", service_data, False)
RAW Paste Data