Time value for numeric state in an automation

Hi to all,

I’m trying to set an automation.
The action should be triggered by a sensor-state, in this case it’s a remaining time. The output-style is hh:mm.
If the time is below a value, in my case it should be 25 minutes, I want to get the action started.
Here starts my problem.

I tried to configure the automation based on a numeric state platform.
When I want to enter the below-value in style of hh:mm I get an error message (Message malformed: Entity ID is an invalid entity ID for dictionary value @ data[‘entity_id’]).

What else can I do to get this automation running?

I’m thankful for every help!

Take a look at this Unable to create new automations in editor · Issue #681 · home-assistant/frontend · GitHub. Make sure you aren’t adding an empty trigger.

If your data really is in the hh:mm format (you can check by looking up your sensor’s state in Developer Tools), you’ll probably need to use the value_template Automation Trigger - Home Assistant to convert it to an integer.

Numerical triggers require a number. Time is not a number. Seconds is a number, minutes is a number, hours is a number. Combined, it’s not a number, its a time. So it will never work with a numerical trigger.

There are a number of ways to solve this. If you want to use a numerical trigger, then you need to take the sensor that is HH:MM and convert it to hours or minutes in a template sensor. In your case, you’d want it in minutes so you can specify 25 in the numerical state trigger.

I believe you can use the numeric state trigger if you extract the number with value_template.
For me, this seems to work just fine:

platform: numeric_state
entity_id: input_text.test
value_template: '{{ state.state.split('':'')[1] }}'
above: '20'

Edit: this of course ignores the hours part of the string, I just wanted to demonstrate that you don’t need a template sensor. See petro’s post below.

1 Like

What happens when you’re at an hour and 1 minute? You didn’t include hours so it will see it as 1 minute. I.E. it needs to be converted from HH:MM to M.

value_template: >
  {% set h, m = state.state.split(':') | map('int') %}
  {{ h * 60 + m }}
1 Like

Thanks so far!

Thats what the automation do look like now:



alias: TEST mit value_template
description: ''
mode: single
trigger:
  - platform: numeric_state
    entity_id: sensor.waschmaschine_remaining_time
    value_template: >
      {% set h, m = sstate.state.split(':') | map(int) %}
      {{ h * 60 + m }}
    below: '25'
condition: []
action:
  - service: notify.mobile_app_iphone_von_paul
    data:
      message: TEST

But there’s still no trigger action.
What could I’ve done wrong?

It will only trigger if the value moves from above 25 to below 25. It will not trigger if it moves from below 25 to below 25.

Also, you have a typo. 2 ss’s on state.state

Oppsi.
Even without the typo there’s still no action.

I’ve tested this while the device was running and the remaining time was counting down from above 25 to below 25.

Can you post the state of the sensor.waschmaschine_remaining_time in the developer tools / states page?

Needs to be map('int') with quotes, as in @petro’s initial response.

alias: TEST mit value_template
id: e5805a2c-4603-4dbe-b683-9973d03f4387

trigger:
  - platform: numeric_state
    entity_id: sensor.waschmaschine_remaining_time
    value_template: >
      {% set h, m = state.state.split(':') | map('int') %}
      {{ h * 60 + m }}
    below: 25

action:
  - service: notify.mobile_app_iphone_von_paul
    data:
      message: TEST

I’ve included an id to allow you to inspect it with the automation tracer / debugger.

It’s ’ 00:00 ’ at the moment.

Ah thanks @Troon! It’s working now.
Thats the final solution!
Even thanks to @petro as well for the main work!

You should mark @petro’s as the solution, really, as his code was right :+1:

1 Like

Doesn’t matter to me, not chasing solutions. Thanks though.

1 Like