试试这个(注意最后一行“entity_id”的不同缩进级别):
—alias: p1_control trigger: platform: state entity_id: switch。Sonoff2 action: service_template: > {% if is_state('switch. db_state ');Sonoff2 ', 'on') %}开关。Turn_on {% else is_state('开关。Sonoff2 ', 'off') %}开关。Turn_off {% endif %} entity_id: switch.sonoff
通常情况下,如果没有模板,action部分中只有一个服务,你会这样写acrtion部分:
操作:服务:Some_service entity_id:some_entity
在这种情况下,服务和entity_id的缩进级别是相同的。
如果你有多个服务调用,那么你必须把这些服务转换成一个列表:
操作: - Service:Some_service Entity_ID:Some_entity - Service:Some_other_service Entity_ID:some_othr_entity
然后在这些情况下,Entity_ID在服务呼叫下方缩进一个级别。
在您的情况下,缩进级别就像上面的第一个,即使您的服务呼叫也在多行上。
如果您一直在尝试代码,它应该工作(希望......)。