help for telegram silent with python

Python and python framework

Moderator: leecollings

Post Reply
david31
Posts: 11
Joined: Thursday 07 January 2016 11:32
Target OS: Linux
Domoticz version: 3.8153
Contact:

help for telegram silent with python

Post by david31 »

Hello

I would like to send a silent message with python.
With LUA on domoticz, it's working fine.
but not in python ...

Code: Select all

def send_mqtt_publish(topic, data):
        data_mqtt = json.dumps(data)
        mqttc.publish(topic, data)

def on_connect(client, userdata, flags, rc):
        mqttc.connected_flag=True
        mqttc.subscribe(MQTT_TOPIC_IN)
        mqttc.subscribe(MQTT_TOPIC_OUT)

mqttc = mqtt.Client()
mqttc.on_connect = on_connect
mqttc.connected_flag=False
mqttc.connect("127.0.0.1", 1883, 60)
mqttc.loop_start()

send_mqtt_publish(MQTT_TOPIC_IN, '{\"command\": \"sendnotification\", \"subject\": \"Alarme\", \"body\": \"Probleme arrosage, intervention immediate\", \"Priority\": -1}')
time.sleep(time_disconnect_mqtt)
mqttc.disconnect()
sys.exit(0)
The flag priority not work ... message have always a sound ...

Sorry for my bad english
User avatar
waltervl
Posts: 5904
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: help for telegram silent with python

Post by waltervl »

what does the log file say? Can it read -1 ? Perhaps try
\"Priority\": \"-1\"}
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
david31
Posts: 11
Joined: Thursday 07 January 2016 11:32
Target OS: Linux
Domoticz version: 3.8153
Contact:

Re: help for telegram silent with python

Post by david31 »

On log file, none error
I have tested, not working ...
User avatar
waltervl
Posts: 5904
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: help for telegram silent with python

Post by waltervl »

According wiki:
"priority": 0 }

So not: Priority (case sensitive)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: help for telegram silent with python

Post by jvdz »

Try using lowercase for priority:

Code: Select all

send_mqtt_publish(MQTT_TOPIC_IN, '{\"command\": \"sendnotification\", \"subject\": \"Alarme\", \"body\": \"Probleme arrosage, intervention immediate\", \"priority\": -1}')
ps: Which version are you running?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
david31
Posts: 11
Joined: Thursday 07 January 2016 11:32
Target OS: Linux
Domoticz version: 3.8153
Contact:

Re: help for telegram silent with python

Post by david31 »

Los case, same problem


Version: 2022.1
Build Hash: c9526851b
Compile Date: 2022-01-31 09:34:32
dzVents Version: 3.1.8
Python Version: 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: help for telegram silent with python

Post by jvdz »

Ok ... Show me the LUA script that is working so I understand what you are doing. :)

(but the parameters in MQTT need to be lowercase!)

Code: Select all

{"command": "sendnotification",
"idx": idx, 
"name": "Some name", 
"subsystem": "target subsystems" 
"subject": "Message Subject", 
"body": "Message Body",
"extradata": "extradata" 
"priority": priority, 
"sound": "mysound",
"brfromnotification": "brfromnotificationdata" }
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
david31
Posts: 11
Joined: Thursday 07 January 2016 11:32
Target OS: Linux
Domoticz version: 3.8153
Contact:

Re: help for telegram silent with python

Post by david31 »

It's working

Code: Select all

send_mqtt_publish(MQTT_TOPIC_IN, '{\"command\": \"sendnotification\", \"subject\": \"Alarme\", \"priority\": -1, \"body\": \"Probleme arrosage, intervention immediate\"}')
low case priority and after subject only

Thanks for all
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: help for telegram silent with python

Post by jvdz »

Do you mean you need to define the priority After the subject field?
This is also working fine for me:

Code: Select all

{"command": "sendnotification", "subsystems": "telegram" ,"priority": -1, "subject": "Alarm", "body": "Test, message2"}
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
david31
Posts: 11
Joined: Thursday 07 January 2016 11:32
Target OS: Linux
Domoticz version: 3.8153
Contact:

Re: help for telegram silent with python

Post by david31 »

If priority is lastest, not work for me ...
Work somewhere

The message is receive all cases
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: help for telegram silent with python

Post by jvdz »

Works for me anywhere I place "priority" and that is what is expected as the JSON is translated into an Object with and you address them through their keywords. SO as long as the JSON is coded correctly things should work irrelevant the sequence of these keywords. ;)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest