arnonym / ha-plugins

Home-Assistant SIP Gateway
Apache License 2.0
157 stars 19 forks source link

Could not deserialize JSON #82

Closed gerard33 closed 5 months ago

gerard33 commented 5 months ago

First of all thanks for this great addon 👍

While making some automations with the choices option I noticed the Could not deserialize JSON error in the log.

The log:

Could not deserialize JSON: "command":"answer","number":"**623**1","menu":{"message":"Hallo, druk op 1 om het plafondlicht in het kantoor aan te doen en op 2 om de lampen in het kantoor aan of uit te doen of op 3 om te stoppen","timeout":30,"choices":{"1":{"id":"plafond","message":"Het plafondlicht in het kantoor is aangezet","action":{"domain":"light","service":"toggle","entity_id":"light.shelly_kantoor"},"post_action":"return"},"2":{"id":"lampen","message":"De lampen in het kantoor zijn aangezet","action":{"domain":"light","service":"toggle","entity_id":["light.lampen_kantoor","light.led_lampjes_lego"]},"post_action":"return"},"3":{"id":"bye","message":"Tot ziens","post_action":"hangup"},"4":{"id":"papa","message":"Papa wordt gebeld","action":{"domain":"script","service":"turn_on","entity_id":"script.call_dad"},"post_action":"noop"},"default":{"id":"wrong_code","message":"Verkeerde code, probeer het opnieuw","post_action":"return"},"timeout":{"id":"timeout","message":"Er is geen keuze gemaakt. Tot ziens","post_action":"hangup"}}}}

when checking the JSON it seems there is a } too many at the end:

{
    "message": "Hallo, druk op 1 om het plafondlicht in het kantoor aan te doen en op 2 om de lampen in het kantoor aan of uit te doen of op 3 om te stoppen",
    "timeout": 30,
    "choices": {
        "1": {
            "id": "plafond",
            "message": "Het plafondlicht in het kantoor is aangezet",
            "action": {
                "domain": "light",
                "service": "toggle",
                "entity_id": "light.shelly_kantoor"
            },
            "post_action": "return"
        },
        "2": {
            "id": "lampen",
            "message": "De lampen in het kantoor zijn aangezet",
            "action": {
                "domain": "light",
                "service": "toggle",
                "entity_id": [
                    "light.lampen_kantoor",
                    "light.led_lampjes_lego"
                ]
            },
            "post_action": "return"
        },
        "3": {
            "id": "bye",
            "message": "Tot ziens",
            "post_action": "hangup"
        },
        "4": {
            "id": "papa",
            "message": "Papa wordt gebeld",
            "action": {
                "domain": "script",
                "service": "turn_on",
                "entity_id": "script.call_dad"
            },
            "post_action": "noop"
        },
        "default": {
            "id": "wrong_code",
            "message": "Verkeerde code, probeer het opnieuw",
            "post_action": "return"
        },
        "timeout": {
            "id": "timeout",
            "message": "Er is geen keuze gemaakt. Tot ziens",
            "post_action": "hangup"
        }
    }
}
}

This issue was also mentioned here --> https://github.com/arnonym/ha-plugins/issues/80#issuecomment-1890785286

The menu is still being played, but I noticed that is not working all the times. Not sure if that's related though.

There is no difference when using:

- service: hassio.addon_stdin
  data:

or

- service: hassio.addon_stdin
  data_template:
gerard33 commented 5 months ago

It seems the issue is caused by restarting the Home Assistant automation unintendedly. So the automation runs when the webhook incoming_call is received, but then runs again on webhook call_established etc. Probably the second run causes the deserialize JSON errors.

I now added an extra condition so the automation only runs on the incoming call and the error doesn't pop up anymore.

condition:
  - "{{ trigger.json.event == 'incoming_call' }}"
arnonym commented 5 months ago

Good find! Thanks for the heads-up!