Hello to everyone!!! i need some help.
Thanks to pnbruckner i have this automation that turn on the boolean sensor:
- trigger:
platform: state
entity_id:
- sensor.0x00158d0002b1136c_action
- sensor.0x00158d0002af6ac2_action
condition:
condition: template
value_template: >
{{ trigger.to_state is not none
and trigger.to_state.state in ('vibration', 'tilt', 'drop')
and (trigger.from_state is none
or trigger.to_state.state != trigger.from_state.state) }}
action:
service_template: >
{% if trigger.to_state.state in ('vibration', 'tilt', 'drop') %}
input_boolean.turn_on
{% else %}
input_boolean.turn_off
{% endif %}
data_template:
entity_id: >
{% if trigger.entity_id == 'sensor.0x00158d0002b1136c_action' %}
input_boolean.finestra_studio
{% else %}
input_boolean.porta_blindata
{% endif %}
No i want to do one automation that run when the boolean sensor turn On, wait 10 seconds then turn off the boolean sensor.
I donât kno how can i do this⌠using this code not workingâŚ
- trigger:
platform: state
entity_id:
- input_boolean.porta_blindata
- input_boolean.finestra_studio
condition:
condition: template
value_template: >
{{ input_boolen is on
}}
action:
service_template: >
input_boolean.turn_off
data_template:
entity_id: >
{% if trigger.entity_id == 'input_boolean.finestra_studio' %}
input_boolean.finestra_studio
{% else %}
input_boolean.porta_blindata
{% endif %}
I believe you meant to say input_boolean not boolean sensor. The automation you have enables/disables an input_boolean.
In Home Assistant, sensors are read-only devices whereas an input_boolean can be turned on/off (like in your automation).
The error message is reporting that your automationâs action calls a service with a name that is incorrectly formatted:
Invalid data for call_service at pos 1: Service does not match format .
Look at the service_template. It contains an if-else. What does it produce for the else? The answer is: nothing. That means the service it will call is no service at all and that is invalid (and responsible for generating the error message). A service_template must produce a valid service name.
Iâve reformatted your automation so you can see the source of the problem clearly:
- id: '1570087617286'
alias: Sensori Vibrazione a Boolean
trigger:
- entity_id:
- sensor.0x00158d0002b1136c_action
- sensor.0x00158d0002af6ac2_action
platform: state
condition:
- condition: template
value_template: >
{{ trigger.from_state is none or trigger.to_state is none
or trigger.to_state.state != trigger.from_state.state }}
action:
service_template: >
{% if trigger.to_state is not none and trigger.to_state.state in ('vibration', 'tilt', 'drop') %}
input_boolean.turn_on
{% else %}
# some other service name has to go here or the template needs to be restructured
{% endif %}
data_template:
entity_id: >
{% if trigger.entity_id == 'sensor.0x00158d0002b1136c_action' %}
input_boolean.finestra_studio
{% else %}
input_boolean.porta_blindata
{% endif %}
The easiest way is just to have another condition in the conditions section so that the automation doesnât run at all. If you have subsequent actions that need to be executed, you could define an empty script and run that in the else block.
There appears to be a contradiction in the automation.
The condition contains trigger.to_state is none
value_template: "{{ trigger.from_state is none\n or trigger.to_state is none\n\
\ or trigger.to_state.state != trigger.from_state.state }}\n"
The actionâs service_template contains trigger.to_state is not none
service_template: "{% if trigger.to_state is not none\n and trigger.to_state.state\
\ in ('vibration', 'tilt', 'drop') %}\n input_boolean.turn_on\n{% else %} \
\ {% endif %}\n"
So the condition allows trigger.to_state to be none but the service_template does not. Why does the condition allow it?
I donât know why, but I need that the automation will run when the sensors stay in Vibration,Tilt or drop state.
I only need this, if sensors stay in Vibration or tilt or drop run the automation, find which sensor has triggered the automation and turn the respective Boolean to ON.
How can I make this automation?
I think something like this:
Edit: Iâm clearly answering a question that has already been answered
I was just suggesting to move the if statement you have in the service_template section into a condition:
- id: '1570087617286'
alias: Sensori Vibrazione a Boolean
trigger:
- entity_id:
- sensor.0x00158d0002b1136c_action
- sensor.0x00158d0002af6ac2_action
platform: state
condition:
- condition: template
value_template: >
{{ (trigger.from_state is none)
or (trigger.to_state is none)
or (trigger.to_state.state != trigger.from_state.state) }}
- condition: template
value_template: >
{{ (trigger.to_state is not none)
and trigger.to_state.state in ['vibration', 'tilt', 'drop'] }}
action:
service: input_boolean.turn_on
data_template:
entity_id: >
{% if trigger.entity_id == 'sensor.0x00158d0002b1136c_action' %}
input_boolean.finestra_studio
{% else %}
input_boolean.porta_blindata
{% endif %}
Also, like Taras mentioned, you check for the from_state and to_state being none several times. Does this normally happen? This is never a check Iâve had to perform. And if trigger.to_state == trigger.from_state then I donât think the automation would have been triggered at all.
pnbruckner had explained (canât find the relevant post at the moment) that if you donât specify a to: and/or from: for a State Trigger, then its open to the possibility of triggering if one of the entityâs attributes changes state.
So if the entityâs state hasnât changed, just one of its attributes, then its to_state.state remains the same as its from_state.state. If theyâre the same then you know the cause of the trigger was some attribute changing. That kind of state-change might not be of interest for automationâs purposes and can be filtered out in the condition.
EDIT
Found it and itâs worth reading through the entire thread. Itâs not one of my shining moments. I challenged Phil on the need for something I disparaged as being a âbelt and suspendersâ approach ⌠and lost the debate but came out wiser (thanks to Philâs patience).
After re-reading that thread, I realize the condition used in this automation should change to this:
condition:
condition: template
value_template: >
{{ trigger.from_state and trigger.to_state and
trigger.from_state.state != trigger.to_state.state and
trigger.to_state.state in ('vibration', 'tilt', 'drop') }}
The first two tests in the template are to ensure the from_state object and to_state object exist before getting to the third test that checks if both object have the same state. As per Philâs explanation in the linked thread, trigger.from_state is shorthand for trigger.from_state is not none (i.e. itâs confirming the object exists).
If that condition evaluates to True then the action can use service (not service_template) to simply call input_boolean.turn_on (there will no longer be a need for an if-else).
Putting it all together, we get this:
- id: '1570087617286'
alias: Sensori Vibrazione a Boolean
trigger:
- platform: state
entity_id:
- sensor.0x00158d0002b1136c_action
- sensor.0x00158d0002af6ac2_action
condition:
condition: template
value_template: >
{{ trigger.from_state and trigger.to_state and
trigger.from_state.state != trigger.to_state.state and
trigger.to_state.state in ('vibration', 'tilt', 'drop') }}
action:
service: input_boolean.turn_on
data_template:
entity_id: >
{% if trigger.entity_id == 'sensor.0x00158d0002b1136c_action' %}
input_boolean.finestra_studio
{% else %}
input_boolean.porta_blindata
{% endif %}
First, thanks for jumping in and helping out. I helped @Wes93 quite a bit in a private message (with 55 posts), so much of the background is not visible to everyone. Unfortunately he is inconsistent in his use of terminology and often changes things without providing complete details, which makes it more difficult to help. Hence I was ready to pass the baton.
FWIW, this was (I think) the last suggestion I had provided on turning the input_boolean on and off:
- trigger:
platform: state
entity_id:
- sensor.0x00158d0002b1136c_action
- sensor.0x00158d0002af6ac2_action
condition:
condition: template
value_template: >
{{ trigger.from_state is none
or trigger.to_state is none
or trigger.to_state.state != trigger.from_state.state }}
action:
service_template: >
{% if trigger.to_state is not none
and trigger.to_state.state in ('vibration', 'tilt', 'drop') %}
input_boolean.turn_on
{% else %}
input_boolean.turn_off
{% endif %}
data_template:
entity_id: >
{% if trigger.entity_id == 'sensor.0x00158d0002b1136c_action' %}
input_boolean.finestra_studio
{% else %}
input_boolean.porta_blindata
{% endif %}
The idea was if the trigger fired either because the sensor was just created (trigger.from_state is none), or the sensor was just deleted (trigger.to-state is none), or if the actual state string changed (trigger.to_state.state != trigger.from_state.state), then run the action, which would either turn the input_boolean on or off depending on the actual state change.
But because these sensors used in the triggers change so fast, it also causes the input_boolean to change too fast for how he was using it. So heâs trying to come up with a way to turn it on as before, but somehow cause it to stay on long enough so âdown the roadâ automations, etc. work correctly. Hence (I assume) why he changed the original automation to attempt to not turn the input_boolean off, but try to do that another way.
Thanks to everyone for the help!! @pnbruckner sorry for my incorrect use of terminology and for changing things and thank for your patienceâŚ
I donât know very well EnglishâŚ
I have changed things because the automation that we have created wonât work so I have used a different approach and for this reason I donât need that the first automation also turn off the sensor.
Anyway really thanks a lot to everyone for the help Iâm a newbie and I need exercise. @123 when I will come Back at home I will try your automation!!
For everyone sorry for the disturbâŚ