- resource: 'http://localhost/local/xml/test.xml'
sensor:
- name: XML date
value_template: "{{ value_json.root.Date }}"
- name: XML time
value_template: "{{ value_json.root.time }}"
For this purpose I created the following automation:
alias: test
description: ""
trigger:
- platform: state
entity_id:
- sensor.xml_date
- sensor.xml_time
condition: []
action:
- device_id: x1x2x3x4x5x6x7x8x9x0x
domain: mobile_app
type: notify
message: test message
title: Attention
mode: single
The automation as such also works wonderfully. However, when I restart HomeAssistant once, the automation is always executed, although the XML has not changed.
Can anyone tell me how to prevent this phenomenon?
this is just a copy&paste error. Here’s the correct formated:
- resource: 'http://localhost/local/xml/test.xml'
sensor:
- name: XML date
value_template: "{{ value_json.root.date }}"
- name: XML time
value_template: "{{ value_json.root.time }}"
alias: test
description: ""
trigger:
- platform: state
entity_id:
- sensor.xml_date
- sensor.xml_time
condition: []
action:
- device_id: x1x2x3x4x5x6x7x8x9x0x
domain: mobile_app
type: notify
message: test message
title: Attention
mode: single
What’s the state of those at startup? If they are unknown, then at startup it will go from unknown to a value, causing it to trigger. You’d have to account for that.
The state has to be changing for it to trigger. There’s no way around that. It’s your job to figure out what states are causing the trigger to occur. You can see this by viewing the trace that happened after startup. It will show you the before and after state.
Let’s assume it works like this:
On startup, the REST Sensor’s initial value is unknown or unavailable and then gets a nominal value the moment the REST integration acquires a value from test.xml. In that case, the change from unknown to the nominal value will trigger your automation’s State Trigger.
You can make the State Trigger ignore that kind of state-change by using its not_from option.
alias: test
description: ""
trigger:
- platform: state
entity_id:
- sensor.xml_date
- sensor.xml_time
not_from:
- unknown
- unavailable
condition: []
action:
- device_id: x1x2x3x4x5x6x7x8x9x0x
domain: mobile_app
type: notify
message: test message
title: Attention
mode: single
thank you for the feedback. I checked again and the value of the sensors is reset on quick reload. So I thought that I set as trigger that the status of sensor.xml_date and sensor.xml_time is changed.
However I want to check now with conditions whether sensor.xml_date is equal today, and sensor.xml_time has a maximum difference to the current time of maximally 5 minutes. Unfortunately I can’t get the condition created.
Format of sensor.xml_date is dd.mm.yyyy
Format of sensor.xml_time is HH:MM:SS
For the date condition I found the following template:
It is the same requirement. I tried to include a not_from unknown and unavailable. But the state gets no unknown or unavailable, but directly the time, which is also in the XML.
In the screenshot I did a quick reload at 08:11. Therefore my idea to ignore the automation if the condition is not today and the current time is at most 5 minutes later than the time in the state.
Do either of the two sensors have attributes that change on startup?
Go to Developer Tools > States and post screenshots of sensor.xml_date and sensor.xml_time.
Alternately, try this:
trigger:
- platform: state
entity_id:
- sensor.xml_date
- sensor.xml_time
to:
The presence of the empty to option makes the State Trigger ignore any changes in the entity’s attributes. Only changes to the entity’s state will trigger the State Trigger.
If that version of the State Trigger is still triggered on restart then it means there really is a change in the value of the entity’s state.
adding to: helped. However, after a restart HA turned the to: into to: null. There was still the problem. I then changed it to to: [], and since then there is no notification anymore
alias: test
description: ""
trigger:
- platform: state
entity_id:
- sensor.xml_date
- sensor.xml_time
not_from:
- unknown
- unavailable
to: []
condition: []
action:
- service: notify.xxxxx
data:
message: "{{ states(\"sensor.xml_time\") }}"
mode: single