Sensor template with string format, automatic state change after 5 mn

Hi all,

I have added a new sensor (using template).

When my HA received a new specific email (imap integration works fine with HA) from a provider, I set the sensor value to “PersonInside”. This email contains the alarm sensor that just switch to “PersonInside” state.

Unfortunnetly, the alarm system is not able to send “NoPersonInside” state later…

So, I would like to set the state “NoPersonInside” after 3 ou 5 minutes for example.

Can you provide me the “setState” piece of code ? I’m not able to find an automation service to set the value of a sensor.

The sensor is defined as follow with the value “PersonInside” defined when an email is received :

presence_couloir:
friendly_name: “Présence Couloir”
value_template: >
{% if state_attr(‘sensor.tahoma_mail’, ‘body’)
| replace (’\n’,’’) | replace (’"’,’’) | replace ("=","")
| regex_match (‘TaHoma alerte : .*, votre condition Pr Couloir’, ignorecase=FALSE) %}
PersonInside
{% endif %}

I know that is possible to trigger a change in automation after a specific period of time, but my problem is that I don’t have the line to set the state of “presence_couloir” to “NoPersonInside”.

Many thanks for your help.

Christophe

Simple reply to myself :slight_smile:

I use the following answer to set the state of my sensor using a python_script set_state.py !

Perfect.