Templating delay with milliseconds?

I recently purchased a Xiaomi Gateway and am trying to set up a script to make the device flash as a alert – unfortunately it seems that the “flash” attribute of light components don’t appear to work with the GW’s basic LED light.

Instead, to overcome this, I have a script that turns the the light on and off with a delay between each cycle. This delay is pointing to a shared YAML file with the line milliseconds: 150 that is pulled via an !include line.

I thought it would be easier, nicer and more configurable to use a template to pull this value off of an input_slider element but I’m struggling to get the milliseconds value to pull through.

The issue seems to stem with the ability to template the delay service – HASS has no trouble with the following:

delay: "00:00:{{ states.input_slider.some_seconds.state|int }}"

but fails when the delay is broken down into pieces:

delay:
    milliseconds: "{{ states.input_slider.some_milliseconds.state|int }}"

It seems like the easiest option would be to add milliseconds to the first style of delay, but this only appears to support the hh:mm:ss format, opposed to hh:mm:ss.sss.

Any ideas?

2 Likes

Remove the quotes

For the second option?

I’ve tried both

delay:
    milliseconds: {{ states("input_slider.beacon_delay")|int }}

and

delay: 
    milliseconds: >
        {{ states("input_slider.beacon_delay")|int }}

These both fail, as the check_config script expect an integer for “milliseconds”.

The HH:MM:SS.SSS fails as it expects HH:MM:SS format.

Sorry to bump such an old topic, but struggling with this myself today.

Eventually solved it by doing the following:
delay: "00:00:00:{{ (((states('input_number.random_color_loop_transition_speed') | float) / 2) * 1000) | int }}"

I then realized that this wasn’t supported by home assistant. Assuming https://github.com/home-assistant/home-assistant/pull/16401 is accepted, this should then be possible.