I tried to update a widget (buton) when I press it. However, when I press, the buton is not updated and still waiting for refresh.
The buton is link to a relay (ON/OFF) when I press it. (relay1_data_widget)
How to update a buton with Python ?
Thanks for your help
Here is the code when I receive a Mqtt message :
Cayenne widget information according to the Dashboard.
ID = ‘v1/’+ MQTT_USERNAME + ‘/things/’ + MQTT_CLIENT_ID
Buton1_cmd = ID + ‘/cmd/2’ # Bouton 1 -> receive Actuator command
Buton1_data = ID + ‘/data/2’ # Bouton 1 -> send Actuator Updated Value
The callback for when a message is received from Cayenne.
print("message received: " + str(message)) m = message.topic.split('/') p = message.payload.decode().split(',') channel = m state = p print("") print("message received from Cayenne mydevice") print("channel =" + str(channel) + " state = " + str(state)) client.mqttPublish(client.rootTopic + '/cmd/2', '1') if channel=='2': if state=='1': client.publish(Buton1_data, "1") print("Bouton 1 is ON") B1 = "on" else: client.publish(Buton1_data, "0") print("Relai 1 is OFF") R1 = "off"
client = mqtt.Client(MQTT_CLIENT_ID)
client.on_message = on_message
Based on DOC : Send Actuator Updated Value
In order to let the dashboard know of the current status of an actuator, the device must publish that value to the corresponding channel. This will ensure that the widget state (on/off) remains consistent with the state of the actuator.
|v1/ username /things/ clientID /data/channel||X|
Payload must contain simply the true binary value of a digital actuator (1/0) or numerical value for analog actuators.
- (string) 1
- (string) 0.8