I’ve create a sensor which gets me a json, and i’ve got a value im looking for from this json and updating in to an entity.
My second though is reuse this data, but with some value edit.
For example, i am getting ‘新北市板橋區123路abc巷78號
I want to create another sensor, but remove the first 6 characters and remove all characters after 巷 (if there are).
From example above, i wish to get ‘123路abc巷’. The’新北市板橋區’ and ‘78號’ are removed.
I am having hard time to test below code as most of the time the value is ‘none’ when i am able to do test.
sensor:
- platform: rest
name: "垃圾車當前位置"
resource: https://crd-rubbish.epd.ntpc.gov.tw/dispProject/api/line-status.ashx?lineid=244025
value_template: "{{ value_json['data']['place'] }}"
scan_interval: 300
- platform: template
sensors:
garbage_truck_location:
friendly_name: "Garbage Truck Location"
value_template: >-
{% set location = states('sensor.垃圾車當前位置') %}
{% set location = location[6:] %}
{% set location = location.split('巷')[0] + '巷' %}
{{ location }}
Another questions is, if i am getting multiple value from a json. Would it be possible to select which one to use by checking the value from json? Like using a if ‘value’ contain ‘abc’, then json[0], else json[1] type of logic?