configuration.yaml

input_text:
container_name:
name: 集装箱名称
initial: "黑色集装箱"
min: 1
max: 60
pattern: "[一-龥a-zA-Z0-9]+"# 只允许中文、字母和数字
sensor:
  - platform: rest
name: 集装箱区域查询
resource_template: "http://python.lzychina.com:8000/say_name_get_area.html?name={{ states('input_text.container_name') | urlencode }}"
value_template: >
{%if'<body>'in value %}
{%setbody_start = value.find('<body>') + 6%}
{%setbody_end = value.find('</body>', body_start) %}
{{ (value[body_start:body_end] ifbody_end > body_startelse value) | striptags | trim }}
{%else%}
        "解析失败: 无有效内容"
{%endif%}
#value_template: "{{value_json.area}}" #返回json格式
json_attributes_path: "$."
json_attributes:
      - area
scan_interval: 3# 60秒更新一次,建议不低于30秒?为什么呢
ui-lovelace.yaml里添加:
views:
  - title: 集装箱查询
    cards:
      - type: entities
        title: 集装箱区域查询
        entities:
          - entity: input_text.container_name
            name: 输入集装箱名称
          - type: button
            name: 立即查询
            tap_action:
              action: call-service
              service: homeassistant.update_entity
              service_data:
                entity_id: sensor.container_area_query
          - entity: sensor.container_area_query
            name: 所在区域
            # 显示查询结果的area属性
            attribute: area
重启之后如下:
在仓库这边输入要查询的内容,在传感器端就能返回正确的查询值。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。