Script already running

Hi all,

I’m wrestling with a problem I hope y’all can help with.

My primary screen displays two picture element cards (one for each floor of the house) onto which I overlay lighting/motion and temp/humidity.

The two floor cards share a small number of elements, but not all need an immediate update. Things like light switches and motion need a near-immediate update on the picture elements cards, whereas temp/humidity and dimming for nighttime/sun angle/cloud cover change slowly and can be updated periodically on a timer.

Rather than allowing all the inputs to update the cards, I have created a 1 min heartbeat signal that updates both picture elements cards regularly. This way I know the cards are no more than 1 min out of step, and it reduces the number of updates and makes maintenance much easier.

The seems to function correctly and reliably, the problem is it fills the log with “Script already running messages”.

Relevant configs are:

switches.yaml - template switch on which the picture element cards are updated

platform: template
switches:
  heartbeat:
    turn_on:
      service: switch.toggle
      data:
        entity_id: switch.heartbeat
    turn_off:
      service: switch.toggle
      data:
        entity_id: switch.heartbeat

automations.yaml - call the toggle service periodically

alias: Toggle heartbeat
description: Used to update events every minute
trigger:
  - platform: time_pattern
    minutes: /01
condition: []
action:
  - service: switch.toggle
    data: {}
    entity_id: switch.heartbeat
mode: single

I understand that for single mode this is intended behaviour, but I am not understanding why the automation is not completing before the next periodic trigger a minute later.

What am I doing wrong?

All best,
Chris.

I’m not sure exactly, but I don’t think that template switch is very good as it doesn’t have a value template and it just turns itself on and off, which in turn turns itself on and off, which in turn…

So I’m surprised that you’re not getting some kind of infinite loop error.

Lose the template switch and use a simple input_boolean instead…

input_boolean:
  heartbeat:

Then adapt your automation

alias: Toggle heartbeat
trigger:
  platform: time_pattern
  minutes: "/1" 
action:
  service: input_boolean.toggle
  entity_id: input_boolean.heartbeat

Why is this even needed… The temperature’s and information will be updated when they update. Why force an update?

Hi Marc,

That was precisely the issue, your simplification works perfectly. I think you were right in that it was causing a loop - I suspect that is what the log message was telling me.

Thank you so much for taking the time to respond, its very much appreciated.

All best,
Chris.

1 Like

Hi Petro,

Why is this even needed… The temperature’s and information will be updated when they update. Why force an update?

I am concerned that free-for-all updates on many entities will lead to too frequent updates (over a low bandwidth connection - Nabu Casa on my mobile, for example). I have opted to control this - and can slow it out as required, only allowing high priority updates to make an immediate change. I currently have about 40 sensors/info sources feeding the two picture elements cards, but am planning more.

Do you think this solution is overkill?

I really appreciate your taking the time to respond.

All best,
Chris.

It simply won’t work. You’ll end up updating the system more because the sensors will be updating at their normal frequency but you just added a heartbeat to update it on a period as well.

1 Like