Defining per-template-sensor trigger in a package with other template sensors

Hi,

I’m using YAML packages to organize all my stuff.

Is there a way to define a custom trigger for only a strict subset of the template sensors defined within a “template:” directive?

Example:

template:
  sensor:
    - name: net_power_production
      unit_of_measurement: "kW"
      state: >
        {% set raw_consumption = states('sensor.energy_meter_electric_consumption_w') | float %}
        {{ raw_consumption * -1 * 0.001 }}

      availability: >
        {{ has_value('sensor.energy_meter_electric_consumption_w') }}

    - name: "Grill Propane Percentage"
      state: >
        {{ ((states('sensor.grill_tank_level') | float(1.5) - 1.5) * 11.77) | round(0) }}
      unit_of_measurement: "%"
      icon: mdi:propane-tank
      availability: >
        {{ has_value('sensor.grill_tank_level') }}

The grill level (using Mopeka) goes unavailable often, so I want to define a template sensor for that one that is basically has_value(‘sensor.grill_tank_level’) so that I can always view the last-known value instead of seeing it as “unavailable” on my dashboard.

But I don’t want to affect the trigger of the net power production.

Thanks!
Matt

As long as you properly delineate the items of the list, yes you can have both trigger-based and state-based template sensors in the same package file:

template:
  - sensor:
      - name: net_power_production
        unit_of_measurement: "kW"
        state: >
          {% set raw_consumption = states('sensor.energy_meter_electric_consumption_w') | float %}
          {{ raw_consumption * -1 * 0.001 }}
        availability: >
          {{ has_value('sensor.energy_meter_electric_consumption_w') }}

  - trigger:
      - platform: state
        entity_id: sensor.grill_tank_level
        not_to:
          - unknown
          - unavailable
    sensor:
      - name: "Grill Propane Percentage"
        state: >
          {{ (( trigger.to_state.state | float(1.5) - 1.5) * 11.77) | round(0) }}
        unit_of_measurement: "%"
        icon: mdi:propane-tank
1 Like