My time TTS annoucement flow suddently doesn't work

Hello folks,

The below node red flow has been working for years but I haven’t paid attention to which update and caused it doesn’t work anymore. There is no error regarding the flow in node red add-on log. Can anyone shed some lights on it?

Below flow is simplified as a demonstration of error. Whenever the condition matches the time it sends the payload.msg to TTS call service node.

I have put a debug node after Format Time node and it is showing time format correctly (say 12:59:59 AM, string) but when the time hit the condition of Announce node, the msg.payload isn’t sent out to link out node, which is actually linked to TTS call service node for some reason.

TTS Time Reporting Flow

[{"id":"b115909b207738ff","type":"inject","z":"8977f8fd.87a5b8","name":"","props":[{"p":"payload"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":470,"y":460,"wires":[["6c39e1d9.a4ab1"]]},{"id":"6c39e1d9.a4ab1","type":"function","z":"8977f8fd.87a5b8","name":"Format Time","func":"function gethour() {\n var time = new Date().toLocaleTimeString();\n return time;\n}\n\nvar time = gethour();\nreturn { payload : time };","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":420,"wires":[["844ff42f6bc70c37"]]},{"id":"844ff42f6bc70c37","type":"function","z":"8977f8fd.87a5b8","name":"Annouce","func":"//12:00 AM\nif (msg.payload == \"11:59:59 PM\")\n{\n    msg.payload = { \n        \"data\":{ \"message\":\"Twelve O Clock\" }\n    }\n    return msg;\n  }\n\n//12:30AM\nif (msg.payload == \"12:29:59 AM\")\n{\n    msg.payload = { \n        \"data\": { \"message\": \"Twelve Thirty\" }\n    }\n    return msg;\n  }\n\n//01:00AM\nif (msg.payload == \"12:59:59 AM\")\n{\n    msg.payload = { \n        \"data\": { \"message\": \"One O Clock\" }\n    }\n    return msg;\n  }","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":360,"wires":[["1e890454.9f15bc"]]},{"id":"1e890454.9f15bc","type":"link out","z":"8977f8fd.87a5b8","name":"Time TTS Out-Link","links":["3d4e0170.853a4e"],"x":975,"y":420,"wires":[]}]

Something has changed in the timeformat.
It has some unknown character between time and AM/PM.

I copied the output of a debug and pasted it in a new line, then edited the time slightly and it triggers fine.

But is this only talking three times a day?

@Hellis81 Nah, the real node is TTS-ing half an hour for 24 x 7. I just simplified the if then inside Annouce node and post here for easier reading lol. The actual annouce node has 24 if then statments.

Ah!! this strange character ruins the flow. Thank you very much!!

I would suggest you use a sensor to create the times that it should trigger then use the time node in Node red.

This template should give you the next time of announcement:

sensor:
  - platform: template
    sensors:
      next_announcement:
        value_template: >-
                         {% if now().minute > 30 %}
                           {{ now().replace(minute=0, second=0, microsecond=0)- timedelta(seconds =1) + timedelta(hours = 1) }}
                         {% else %}
                           {{ now().replace(minute=30, second=0, microsecond=0)- timedelta(seconds =1) }}
                         {% endif %}

And probably is usable in a time node.

@Hellis81 how do it setup the time node and the announcement function?

If we expand the template sensor to:

sensor:
  - platform: template
    sensors:
      next_announcement:
        value_template: >-
                         {% if now().minute > 30 %}
                           {{ now().replace(minute=0, second=0, microsecond=0)- timedelta(seconds =1) + timedelta(hours = 1) }}
                         {% else %}
                           {{ now().replace(minute=30, second=0, microsecond=0)- timedelta(seconds =1) }}
                         {% endif %}
        attribute_templates: 
          time: >-
                         {% if now().minute > 30 %}
                           {{ (now().replace(minute=0, second=0, microsecond=0) + timedelta(hours = 1)).strftime('%-H') }} O clock
                         {% else %}
                           {{ now().replace(minute=30, second=0, microsecond=0).strftime('%-H') }} {{ now().replace(minute=30, second=0, microsecond=0).strftime('%-M') }} 
                         {% endif %}

Then you get an attribute with the spoken message. I have not been able to test it since I’m not home but I believe if you have the string 12 30 then it will read it out as twelve thirty.

Anyways I believe this should work:

[{"id":"d2cf6f1d0fa90f18","type":"api-call-service","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":5,"debugenabled":false,"domain":"tts","service":"cloud_say","areaId":[],"deviceId":[],"entityId":["media_player.your_media_player"],"data":"{ \t    \"message\": msg.data.attributes.time\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":510,"y":800,"wires":[[]]},{"id":"45ae3ac4b9c97916","type":"ha-time","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"sensor.next_announcement","property":"","offset":"0","offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"sunday":true,"monday":true,"tuesday":true,"wednesday":true,"thursday":true,"friday":true,"saturday":true,"debugenabled":false,"x":230,"y":800,"wires":[["d2cf6f1d0fa90f18","527d61909384a2d1"]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

You just need to change the media player in the call service node if you have the sensor as above.