#beginner looking for some help building a script

1 messages · Page 1 of 1 (latest)

dire wave
#

Hello. I have a script that started, but when it comes to the actions I don't know how to do it. I think it will require templating. Was hoping someone may find it interesting enough to lend a hand.

Here's the first part of it:

alias: "Convert time spent: Work Training into Personal Education Credits"
sequence: []
mode: single
icon: mdi:cash-fast

Here's the part that I don't know how to code. Basically I just want to take the value from a number input box that's on a dashboard, divide it by 3 and then add that value to another counter. Oh yeah and then clear the input number field after it's done so that it can be re-used again.

$credits_to_add = "input_number.minutes_to_add" / 3

add $credits_to_add to "counter.time_credits_personal_education"

clear "input_number.minutes_to_add"
#

Ah Ha I got the first part. I can read the number of minutes entered into the text field using this

{{ states('input_number.minutes_to_add') }}
#

ooo and I divide it by doing this

{{ states('input_number.minutes_to_add') | float / 3 }}
#

And I made a second input box so that I can add Hours and Minutes and did a calculation like this

{{ states('input_number.minutes_to_add') }}
{{ states('input_number.hours_to_add') | float * 60 }}
#

It outputs the numbers in the template box
15.0
120.0

Now have to figure out how to add the numbers together

#

Ah ha. It works like this:

{{ (states('input_number.minutes_to_add') | float) + (states('input_number.hours_to_add') | float * 60) }}
#

Ok so now I'm able to read the amount of minutes to add to a counter.. but how do I add them to the counter...

#

Yar. ok this is not as straightforward as I thoght.