|
本帖最后由 shigubin 于 2024-12-21 23:02 编辑
sensor:
- platform: rest
name: Smart Light All States
unique_id: smart_light_all_states
resource: http://www/api/device/states
method: POST
headers:
Content-Type: "application/json; charset=UTF-8"
payload: >
{
"deviceSn": "123"
}
value_template: >
{{ (value_json.result | length) | default(0) }}
json_attributes:
- result
scan_interval: 10
template:
- sensor:
- name: "Restaurant Light State"
unique_id: "restaurant_light_state"
state: >
{{ (state_attr('sensor.smart_light_all_states', 'result')
| selectattr('st', '==', 10101)
| selectattr('si', '==', 1)
| map(attribute='fv')
| list | first | default(0)) }}
- name: "Living Room Light State"
unique_id: "living_room_light_state"
state: >
{{ (state_attr('sensor.smart_light_all_states', 'result')
| selectattr('st', '==', 10101)
| selectattr('si', '==', 2)
| map(attribute='fv')
| list | first | default(0)) }}
light:
- platform: template
lights:
restaurant_light:
unique_id: "restaurant_light_switch"
value_template: "{{ is_state('sensor.restaurant_light_state', '1') }}"
turn_on:
sequence:
- service: rest_command.restaurant_light_on
- service: homeassistant.update_entity
data:
entity_id:
sensor.smart_light_all_states
- service: homeassistant.update_entity
data:
entity_id:
sensor.restaurant_light_state
turn_off:
sequence:
- service: rest_command.restaurant_light_off
- service: homeassistant.update_entity
data:
entity_id:
sensor.smart_light_all_states
- service: homeassistant.update_entity
data:
entity_id:
sensor.restaurant_light_state
living_light:
unique_id: "living_light_switch"
value_template: "{{ is_state('sensor.living_room_light_state', '1') }}"
turn_on:
sequence:
- service: rest_command.living_light_on
- service: homeassistant.update_entity
data:
entity_id: sensor.smart_light_all_states
turn_off:
sequence:
- service: rest_command.living_light_off
- service: homeassistant.update_entity
data:
entity_id: sensor.smart_light_all_states
rest_command:
restaurant_light_on:
url: "http://www/api/device/control"
method: post
headers:
Content-Type: "application/json; charset=UTF-8"
payload: >
{
"deviceSn": "123",
"fn": 1,
"fv": 1,
"si": 1,
"st": 10101
}
restaurant_light_off:
url: "http://www/api/device/control"
method: post
,
"st": 10101
}
living_light_on:
url: "http://www/api/device/control"
method: post
headers:
Content-Type: "application/json; charset=UTF-8"
payload: >
{
"deviceSn": "123",
"fn": 1,
"fv": 1,
"si": 2,
"st": 10101
}
living_light_off:
url: "http://123/api/device/control"
method: post
headers:
Content-Type: "application/json; charset=UTF-8"
payload: >
{
"deviceSn": "123",
"fn": 1,
"fv": 0,
"si": 2,
"st": 10101
}
这个是我配置的restful api的设备,sensor中配置了两个灯的状态轮询,并且灯的状态是通过这个来确定的,但是我在开灯的时候需要立刻更新这个值才能准确显示灯的状态
但是问题是,我在开灯的时候调用顺序调用homeassistant.update_entity,并没有起作用,有大佬帮忙看下么?
|
|