Trigger Template, How to...?

You are right, the tempalte can be tested in template editor, but I want to test the automation… the conditions…

You can trigger an automation in the call service section of Dev tools.

Then change your trigger to something like an input boolean changing from off->on

That’s the same as running only the actions

The thing is that I made the template result a boolean, still can’t test it from the automation :slight_smile:

Nevermind, I will try more till I get a result. Thank you all for advices

There a check box to include conditions

1 Like

So the time your sensor changed has to be over 1 hour ago but within the last 10 minutes?

That is not possible.

if the sensor changed in first 10 minutes or if over 1 hour (between 10 minutes and 60 minutes, don’t trigger)

Right. Your first explanation had AND.

OR makes more sense.

Try this in the template editor:

{{ as_timestamp(now()) - as_timstamp(states.sensor.your_sensor.last_changed) > 3600 or as_timestamp(now()) - as_timstamp(states.sensor.your_sensor.last_changed) < 600 }}
1 Like

Thank you
There is any way to test it now without waiting the sensor, from automation? :frowning:

No, you have to wait and use the template editor. This is exactly what the template editor is for.

For future reference, this is not conditions either. This is a template, hence why you confused everyone in the thread.

Thirty-three posts and counting; must be April 1st (or a chatbot).

Hey! I thought YOU were the chat bot!

:laughing:

Those things are popping up all the place here lately.

“Negative. I am a meat popsicle.”

3 Likes

Seems that the condition template it is not working, It is acting like bypassing this condition… I made this code (in the middle of the full code) and I still receive the notification between 10 seconds - 60 minutes…

choose:
  - conditions:
      - condition: state
        entity_id: sensor.computer_heater_battery
        state: '5'
    sequence:
      - service: variable.set_variable
        data:
          variable: computer_heater_battery
          value: low
      - condition: template
        value_template: >-
          {{ as_timestamp(now())|int -
          as_timestamp(states.sensor.computer_heater_battery.last_changed)|int <
          10 or as_timestamp(now())|int -
          as_timestamp(states.sensor.computer_heater_battery.last_changed)|int >
          21600 }}
      - service: notify.persistent_notification
        data:
          title: Computer Heater
          message: Battery Low
default: []

Maybe it is acting as bypassing because I didn’t put quotas for the template?

Should be something like this?!

        value_template: >-
          "{{ as_timestamp(now())|int -
          as_timestamp(states.sensor.computer_heater_battery.last_changed)|int <
          10 or as_timestamp(now())|int -
          as_timestamp(states.sensor.computer_heater_battery.last_changed)|int >
          21600 }}"

If is so, why? I mean… what is the importance of this quotas?

Do not quote multi-line templates. Only single line templates.

You are triggering on the state change of sensor.computer_heater_battery. So its last changed value is always going to be less than 10 seconds, thus the condition passes.

1 Like

I tested by changing the state of the sensor manually. I changed between 0-10 seconds, works… then I changed after 10 seconds, I still get the notification :slight_smile:

I think I will set it only after 60 minutes maybe this will work better in this setup

The problem with what I am trying to achieve, is that I want the trigger of the sensor to do two things:

  1. To change the variable anytime, to know if the battery is low or high
  2. To receive a notification only once per hour, if the battery is low

And this makes me to remove the <10 seconds rule, which is more logical to work

The simplest way would be with two automations.

First automation triggers on every change to ‘5’ and sets the variable to low.

Second automation only triggers if the state is ‘5’ for 60 minutes and sends you a notification.

1 Like

Yes, you are right. I don’t know why I am always avoiding to make many automations. I’m just stupid I think :smiley:

Thank you so much for your help. I will wait one hour and test it again.