giuseppecastaldo / ha-addons

Home Assistant Whatsapp Add-on
Apache License 2.0
49 stars 18 forks source link

templating in message #43

Closed nicoolaro closed 5 months ago

nicoolaro commented 9 months ago

Does templating work in text message, i am trying to send a temperature sensor value to message but am not receiving it.

plane text works ok

example:

service: whatsapp.send_message

data:

clientId: default

to: 3****@s.whatsapp.net

body:

text: "{{ states.sensor.livingroom_temperature_temperature.state }}"
PiperNigrum commented 9 months ago

You can use a own Script to call the send message

service: script.whatsapp_send_message data: message: "{{ states('sensor.your_sensor') }}"

Within your script use text: "{{ message }}"

nicoolaro commented 9 months ago

You can use a own Script to call the send message

service: script.whatsapp_send_message data: message: "{{ states('sensor.your_sensor') }}"

Within your script use text: "{{ message }}"

i don't get it, i should creat a script? becasue when i try the code you sent it doesn't work

PiperNigrum commented 9 months ago

You can use a own Script to call the send message

service: script.whatsapp_send_message data: message: "{{ states('sensor.your_sensor') }}"

Within your script use text: "{{ message }}"

i don't get it, i should creat a script? becasue when i try the code you sent it doesn't work

Yes - create a new script which calls the WhatsApp send message.

image

Now you can call your script to pass any message.

image

Hope it is easier to understand :)

nicoolaro commented 9 months ago

You can use a own Script to call the send message

service: script.whatsapp_send_message data: message: "{{ states('sensor.your_sensor') }}"

Within your script use text: "{{ message }}"

i don't get it, i should creat a script? becasue when i try the code you sent it doesn't work

Yes - create a new script which calls the WhatsApp send message.

Now you can call your script to pass any message.

Hope it is easier to understand :)

Thank you for the help much appreaciate it. But message is not sent. I followed to the letter

image

image

Script is executing but i am not receiving a message

PiperNigrum commented 9 months ago

You can use a own Script to call the send message

service: script.whatsapp_send_message data: message: "{{ states('sensor.your_sensor') }}"

Within your script use text: "{{ message }}"

i don't get it, i should creat a script? becasue when i try the code you sent it doesn't work

Yes - create a new script which calls the WhatsApp send message.

Now you can call your script to pass any message.

Hope it is easier to understand :)

Thank you for the help much appreaciate it. But message is not sent.

I followed to the letter

image

image

Script is executing but i am not receiving a message

Well try to Check your script with a fix text - e.g. "Test"? Does it work?

Maybe your sensor is invalid or is null?

I've tried my script and passed no Text (" "). I did not get a message as well...

nicoolaro commented 9 months ago

You can use a own Script to call the send message

service: script.whatsapp_send_message data: message: "{{ states('sensor.your_sensor') }}"

Within your script use text: "{{ message }}"

i don't get it, i should creat a script? becasue when i try the code you sent it doesn't work

Yes - create a new script which calls the WhatsApp send message.

Now you can call your script to pass any message.

Hope it is easier to understand :)

Thank you for the help much appreaciate it. But message is not sent. I followed to the letter image image Script is executing but i am not receiving a message

Well try to Check your script with a fix text - e.g. "Test"? Does it work?

Maybe your sensor is invalid or is null?

I've tried my script and passed no Text (" "). I did not get a message as well...

Nope, fixed works, template don't. I tried with Telegram and all is ok , Whataspp doesn't work. Oh well i'll continue debugging, thanks for your help!

chonnymon commented 9 months ago

You can use a own Script to call the send message

service: script.whatsapp_send_message data: message: "{{ states('sensor.your_sensor') }}"

Within your script use text: "{{ message }}"

i don't get it, i should creat a script? becasue when i try the code you sent it doesn't work

Yes - create a new script which calls the WhatsApp send message.

Now you can call your script to pass any message.

Hope it is easier to understand :)

Thank you for the help much appreaciate it. But message is not sent. I followed to the letter image image Script is executing but i am not receiving a message

Well try to Check your script with a fix text - e.g. "Test"? Does it work? Maybe your sensor is invalid or is null? I've tried my script and passed no Text (" "). I did not get a message as well...

Nope, fixed works, template don't. I tried with Telegram and all is ok , Whataspp doesn't work. Oh well i'll continue debugging, thanks for your help!

Hi, i was looking for an answer to this today.

I have found the following format works, straight in the automation

Screenshot

hopefully this is helpful to someone

nicoolaro commented 9 months ago

You can use a own Script to call the send message

service: script.whatsapp_send_message data: message: "{{ states('sensor.your_sensor') }}"

Within your script use text: "{{ message }}"

i don't get it, i should creat a script? becasue when i try the code you sent it doesn't work

Yes - create a new script which calls the WhatsApp send message.

Now you can call your script to pass any message.

Hope it is easier to understand :)

Thank you for the help much appreaciate it. But message is not sent. I followed to the letter image image Script is executing but i am not receiving a message

Well try to Check your script with a fix text - e.g. "Test"? Does it work? Maybe your sensor is invalid or is null? I've tried my script and passed no Text (" "). I did not get a message as well...

Nope, fixed works, template don't. I tried with Telegram and all is ok , Whataspp doesn't work. Oh well i'll continue debugging, thanks for your help!

Hi, i was looking for an answer to this today.

I have found the following format works, straight in the automation

Screenshot

hopefully this is helpful to someone

This worked, thank you!!

kalhimeo commented 6 months ago

This add-on is really amazing, but I am facing the same problem when sending a message containing only numbers (which was probably the same bug that nicoolaro was initially facing with his temperature template.

The add-on log would show this error :

[2024-01-01T23:52:54.177] [ERROR] default - Cannot read properties of undefined (reading 'payload')

Using the Service developer tool, this does not work :

service: whatsapp.send_message
data:
  clientId: default
  to: xxxxxx@s.whatsapp.net
  body:
    text: 1

This does work :

service: whatsapp.send_message
data:
  clientId: default
  to: xxxxxx@s.whatsapp.net
  body:
    text: >-
      1

But a template like this which results in a number output does not work :

service: whatsapp.send_message
data:
  clientId: default
  to: xxxxxx@s.whatsapp.net
  body:
    text: >-
      {{ states('sensor.temperature') }}

Inserting some non-numeric characters is a temporary fix :

service: whatsapp.send_message
data:
  clientId: default
  to: xxxxxx@s.whatsapp.net
  body:
    text: >-
      {{ states('sensor.temperature') }} .

Any idea if this can be fixed on add-on side ?

Thank you very much !

Best regards

Squal165 commented 6 months ago

Try starting your message with text then template value.

service: whatsapp.send_message
data:
  clientId: default
  to: xxxxxx@s.whatsapp.net
  body:
    text: >-
      Temperature value is {{ states('sensor.temperature') }}.
kalhimeo commented 6 months ago

yes that works for sure, as in my temporary fix above where i simply added a "space and a point" at the end. But it would be better if the bug can be fixed :-) Also in my exemple I used a temperature template to make it easy, but in reality I use this add-on in a chatbot answering queries from a WhatsApp conversation, so I cannot use additional fixed text in the template as it can be anything from a number to a long sentence.

kalhimeo commented 5 months ago

I don't know if it s due to the last code reversal from 1.3.4 to 1.3.5, but this bug is unfortunately still present in latest release 1.3.5. Log error when the message is only a number : [2024-01-21T00:20:36.028] [ERROR] default - Cannot read properties of undefined (reading 'payload')

giuseppecastaldo commented 5 months ago

unfortunately I didn't carefully check the latest pull request. the bug is scheduled for fix