2024年11月23日星期六 下午7:26:43

Template sensor: multiple and AND or conditions multi Template condition

5 个月 前
#39336 引用
Template sensor: multiple and AND or conditions
0
5 个月 前
#39337 引用
you can use {% if %} in the template

# Determine when the washing machine has a load running.
binary_sensor:
  - platform: template
    sensors:
      let_it_rain:
        friendly_name: "Regen_Bedingungen"
      
  value_template: >-
          {% if is_state('input_boolean.bewasserung_ein', 'on') and is_state('sensor.wetter_sensor_rain', 'not raining') %}
            {% if is_state('sensor.season', 'spring') or is_state('sensor.season', 'summer') %}
              {% if states('sensor.wetter_sensor_condition')|regex_search("regen", ignorecase=True) %}
                True
              {% endif %}
            {% endif %}
          {% endif %}
0
5 个月 前
#39338 引用
make it more readable you can put them on separate lines but make sure you use the multi-line indicator in the code:

value_template: >
  {{ states('input_boolean.bewasserung_ein') == 'on'
    and states('sensor.wetter_sensor_rain') != 'raining'
    and ('Regen' not in states('sensor.wetter_sensor_condition'))
    and ('summer' in states('sensor.season') or 'spring' in states('sensor.season'))
    }}
0
5 个月 前
#39339 引用
via ui


action:
  - alias: Living room toilet/01
    if:
      - condition: and
        conditions:
          - condition: template
            value_template: |-
              {{  (as_timestamp(now()) -
                                                        as_timestamp(states.binary_sensor.aqara_motion_sensor_t1_cn_version_rtcgq12lm_no3.last_changed))
                                                        > 60 *5      }}
          - condition: template
            value_template: |-
              {{  (as_timestamp(now()) -
                                                        as_timestamp(states.binary_sensor.aqara_high_accuracy_sensor_cn_version_rtcgq13lm.last_changed))
                                                        > 60 *5      }}
                                                         {# Living room toilet  5分钟未检测到人,关灯  #}
    then:
      - service: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.aqara_hub_m1s_edb6_lightbulb
  - alias: Zeit/02
0