I have the following sensor and automation.
When I use an MQTT client and subscribe to OpenZWave/1/node/11/instance/1/commandclass/99/#
it happily spits out 5 retained messages in JSON format. Then let’s say after I subscribe, some events occur which causes 2 more messages to be sent to that subscription. I’d like to process each message, and count the number of messages. In the following I’m expecting to get 7 messages, but am only getting 1.
When I use any simple MQTT client I am getting 7 messages (the 5 retained and 2 new). What am I doing wrong?
sensor:
- platform: mqtt
name: mqttlock
state_topic: "OpenZWave/1/node/11/instance/1/commandclass/99/#"
json_attributes_topic: "OpenZWave/1/node/11/instance/1/commandclass/99/value/#"
value_template: "{{ value_json.TimeStamp }}"
json_attributes_template: "{{ value_json | tojson }}"
automation:
- alias: MQTTuserVal
trigger:
platform: state
entity_id: sensor.mqttlock
action:
- service: input_number.set_value
data_template:
entity_id: input_number.mqcount
value: '{{ (states.input_number.mqcount.state | int ) + 1 }}'