尝试(注意最后一个“Entity_ID”行的不同缩进级别):
- 别名:p1_control触发器:platform:state entity_id:switch.shoff2操作:service_template:> {%if is_state('switch.sonoff2','上')%} switch.turn_on {%else is_state('switch.sonoff2','off')%} switch.turn_off {%ENDIF%} ENTITY_ID:switch.shoff
通常情况下,如果没有模板,action部分中只有一个服务,你会这样写acrtion部分:
操作:service: 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被缩进比服务调用低一级。
在您的情况下,缩进级别与上面的第一个类似,即使您的服务调用在多行上。
如果你尝试上述所有的代码,它应该工作(希望…)。