Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Automation works but YAML is ugly

$
0
0

@ha-username wrote:

I’m using demultiplexers to publish topics for various sensors. Here’s one example:

- alias: OMG Pilight Elro demultiplexer
  id: 1a9a1234b34641c09824f583c33fd9f5
  trigger:
    platform: mqtt
    topic: home/OpenMQTTGateway_ESP8266_RF/PilighttoMQTT
  condition:
  - condition: template
    value_template: '{% if trigger.payload_json.protocol==''elro_800_contact'' %} true
      {% endif %}'
  action:
  - service: mqtt.publish
    data_template:
      topic: '{{ ''homeassistant/binary_sensor/'' + trigger.payload_json.protocol|string + trigger.payload_json.message.systemcode|string + trigger.payload_json.message.unitcode|string + ''/state'' }}'
      payload: 'ON'
  - service: mqtt.publish
    data_template:
      topic: '{{ ''homeassistant/binary_sensor/'' + trigger.payload_json.protocol|string + trigger.payload_json.message.systemcode|string + trigger.payload_json.message.unitcode|string + ''/config'' }}'
      payload: '{"name":"{{trigger.payload_json.protocol|string}}{{trigger.payload_json.message.systemcode|string}}{{trigger.payload_json.message.unitcode|string}}", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/{{trigger.payload_json.protocol|string}}{{trigger.payload_json.message.systemcode|string}}{{trigger.payload_json.message.unitcode|string}}/state"}'

How can I make this shorter? Can I assign variables in the condition somehow? Any other code conventions I should be aware of?

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>