Incrementing a time helper value by a value set in a number helper?

I have the following helpers

Date\time helper (Monday_Starttime_1), containing a time value that I want something to activate on Monday Morning. It’s just a time, rather than a date\time.

Number helper (Monday_Starttime_2) which contains a number representing the number of minutes that I want a delayed action to happen on Monday morning.

For example, the first number will trigger automatic functions such as heating that are needed before people arrive, and the second number represents the time that actions will be performed as people start arriving, such as turning on lights.

I want to have the second number as a number minutes after the first event rather than a fixed time, for a whole bunch of reasons that don’t really matter here, it’s just the way that I want it.

I’m going to set a Wait for this (delay: “”)

I know that the number helper has a decimal place after it, so setting “10” minutes is actually “10.0” minutes .

I also know that the timer runs in seconds, so I need to multiple it by 60, which would give me “600.00” second.

How do I go about, adding the right number of second to delay:

According to this thread the answer should be something along the lines of

`

delay: “{{ (as_timestamp(states(‘input_datetime.Monday_Starttime_1’)+ states(‘input_number.Monday_Starttime_2’) )|timestamp_custom(‘%Y-%m-%d %H:%M:%S’) }}”

`

But I get the error message

Invalid action offset {{ (as_timestamp(states(‘input_datetime.Monday_Starttime_1’)+ states(‘input_number.Monday_Starttime_2’) )|timestamp_custom(‘%Y-%m-%d %H:%M:%S’) }} should be format ‘HH:MM’, ‘HH:MM:SS’ or ‘HH:MM:SS.F’ for dictionary value @ data[0][‘delay’]

I’ve read the documentation but don’t yet understand yaml enough to see where I went wrong, I’m not sure if it’s just syntax or if I HA can’t actually do this.

Yes, I know that I’ve not put the multiplier in to change minutes to seconds, I haven’t gotten quite that far yet.

Waiting for long periods in automations and scripts is not recommended. They can be interrupted by restarts and reloads.

Better if you use two triggers.

Automation 1 (immediate actions)

trigger:
  - platform: time
    at: input_datetime.Monday_Starttime_1

Automation 2 (delayed actions)

trigger:
  - platform: template
    value_template: "{{ now() > today_at(states('input_datetime.Monday_Starttime_1')) + timedelta(minutes=states('input_number.Monday_Starttime_2')) }}"

You could of course complicate this by using the two triggers in the one automation and using a choose action based on the trigger_id to determine which actions run.

It’s usually only 10 to 15 minutes, in the winter so I’m not particularly worried about the timer resetting.

Right now I’m only trying to get proof of concept up and running and I’m going to use this kind of operation elsewhere to merge current and legacy systems together so even if 8 change it here later I need it elsewhere.

So just like your other bun-fight of a topic you are going to ignore good advice and the simple triggers I have provided in favour of your poorly chosen solution.

I’m not going to try to convince you this is a bad idea this time though. Good luck.

2 Likes

Why does everything need to be an argument with you?

If your first reaction at being told “no thank you” is to launch into a rant and to bring up arguments on other threads where you did exactly the same thing, then you have a serious anger management problem.

Every time you enter one of my threads it turns into a battleground. Just accept that I either can’t or don’t want to do things your way, move on, and stop harassing me.

There’s a common theme with your posts and @tom_l isn’t involved in all of them. I think you might want to start looking inward. People will give you suggestions that work well with HA. That may not be what you want, but that doesn’t mean you should dismiss it. It’s rather mind blowing that you continue to open these threads with questions and reject all the answers.


To add a input_datetime with only a time to an input number with minutes…

EDIT: This isn’t correct, this would be for a an input datetime, so I’ll modify this post for that.

service: input_datetime.set_datetime
target:
  entity_id: input_datetime.abc
data:
  datetime: "{{ (today_at(states('input_datetime.xyz')) + timedelta(minutes=states('input_number.abc') | float)).total_seconds() }}"
1 Like

OK, let’s take a step back here. First of all:

  1. @tom_l knows that we don’t get on. Yet they keep responding to my threads, or responding to my comments on other threads.

  2. They keep posting back links to previous comments where we have butted heads, and attempting to continue that same old argument on the new threads.

They could simply ignore me, but they keep coming back and starting the same old argument up again.

If I posted links back to old arguments that you and I had, how how would you feel?

Secondly:

People will give you suggestions that work well with HA. That may not be what you want, but that doesn’t mean you should dismiss it.

To quote myself:

It’s usually only 10 to 15 minutes, in the winter so I’m not particularly worried about the timer resetting.

I really don’t see how not being worried about using a timer to 10-15 minutes warrants two site moderators needing to be involved. This really should be that big a deal. I was polite, I didn’t use bad language and I didn’t insult anyone.

It’s rather mind blowing that you continue to open these threads with questions and reject all the answers.

I didn’t reject the answer. I simply said that I wasn’t worried about using timers for short periods of time.

Look at it from my perspective. I ask what should be a simple question. How to increment one helper using the value in a slightly different helper. That’s all that I asked and all that I’m doing right now in order to complete a single specific task.

Someone comes along and they answer the question but also make several suggestions that I didn’t ask for, and which I’m not looking to follow through on because I just need to get this one thing done and I don’t want to go off at a tangent.

This person then blows up in my face, posts links to old arguments, and tries to restart them.

Now I’m having to defend myself and to explain why I didn’t want to follow someone else’s’ suggestion.

Can people please just accept it when someone else politely says “no” to them.

And if you don’t get on with me, then don’t reply to me.

I stayed in my lane, avoided people I didn’t get along with, and what happens, they come to me, get upset over the same old things, and try to continue old arguments.

Does this sound normal to you?

My man, I was cruising through posts and stumbled on this. We are moderators cause we are always bored on the site helping people :wink: It’s really not about you. I asked tom about this and he didn’t even recognize your name until you turned down his suggestion.

You’re putting yourself on a pedestal, there’s 200k users here. We don’t remember everyone, however I’m starting to remember your posts.

Bit of an overblown statement. His response was more of an “:roll_eyes:, oh it’s you, I’ll leave then”.

1 Like

Anyways, I answered your question above to the exact letter which you’re looking for. No reason to continue this back and forth.

Although, if you’re just looking for a delay from this moment in time… This would probably work too.

EDIT2: Yeah, you really only need this template.

delay: "{{ timedelta(minutes=states('input_number.abc') | float).total_seconds() }}"

This thread is now a warzone, other people coming to this thread looking for an answer to a similar question are now seeing a running argument that started because I politely said that I wasn’t worried about using timers for short periods of time.

This is not helpful to anyone. I’m unlikely to get any alternative suggestions from any other users now. They’re going to see this running battle and are either going to be put off of to join in.

So I end up with one person’s opinion on a solution, and no other views or suggestions of different ways to to it.

You might as well just delete the thread, it’s no longer productive.

my man, just move on, try the answer. I thought I made this clear

Dude, I answered your literal question which differs from Tom’s suggestion. To a T. What other suggestions do you need? You want to delay based off your input number. Do you want an exact copy/paste for you to try?

delay: "{{ timedelta(minutes=states('input_number.monday_starttime_2') | float).total_seconds() }}"

Put it in developer tools → template page. You’ll see it spits out seconds, exactly what’s needed for delay.

I answered your literal question which differs from Tom’s suggestion. To a T. What other suggestions do you need?`

At the risk of setting things off again, some time to try it.

I’m having to sort something else right now, and I’m not with my system.

To be clear, I’m not questioning anyone’s code, I’m just trying to keep my focus narrow and to get one thing finished before I start another.

I’ve put plenty of things that people have suggested by for later consideration, but I want to get proof of concept running first.

I’ve got to figure out how to walk before I try to run, and I need to get some of the basics figured out before I move on to the more complicated things, so it’s a little frustrating when people recommend things that I’m not ready for, or which would mean that I’d need to reimagine or restructure things that I’ve already got functioning while I’m still trying to get more basic things figured out.

I’m using HA to cut my cords to the cloud due to my main service provider ending several important services to anyone who hasn’t brought the latest hardware, so I’ve got a whole bunch of legacy systems and legacy issues.

Some things need doing in a certain way because they need specific inputs or outputs, or because they need to line up with other systems, and some have human elements that they need to fit in with. So the best solution from an HA perspective isn’t always the right solution for me. Sometimes the less optimal way form an HA perspective is the most effective way for me.