hassil icon indicating copy to clipboard operation
hassil copied to clipboard

[Feature] Sentence templates

Open tetele opened this issue 1 year ago • 0 comments

When setting up sentences for binary sensors, it's usually a repetitive process, but with slight variations.

      - sentences:
          - "(is|are) <name> [battery] {bs_battery_states:state} [in <area>]"
        response: one_yesno
        requires_context:
          domain: binary_sensor
          device_class: battery
        slots:
          domain: binary_sensor
          device_class: battery

...

      - sentences:
          - "(is|are) <name> {bs_gas_states:state} [in <area>]"
        response: one_yesno
        requires_context:
          domain: binary_sensor
          device_class: gas
        slots:
          domain: binary_sensor
          device_class: gas

We could define a template sentence in _common.yaml

    sentence_templates:
      is_name_state_in_area:
        sentence: "(is|are) <name> <state> [in <area>]"
        defaults:
          state: "{state}"

write these sentences in a more extensible manner like this

      - sentences:
          - template: is_name_state_in_area
            data:
              name: "<name> [battery]"
              state: "{bs_battery_states:state}"
        response: one_yesno
        requires_context:
          domain: binary_sensor
          device_class: battery
        slots:
          domain: binary_sensor
          device_class: battery

...

      - sentences:
          - template: is_name_state_in_area
            data:
              name: "<name>"
              state: "{bs_gas_states:state}"
        response: one_yesno
        requires_context:
          domain: binary_sensor
          device_class: gas
        slots:
          domain: binary_sensor
          device_class: gas

tetele avatar Mar 01 '23 00:03 tetele