Zigbee2mqtt changes the time exactly every hour

Platform information:
Ubuntu Server 16.04.7
Mosquitto ver. 2.0.7
openHAB 2 ver. 2.5.5
zigbee2mqtt ver. 1.17.1

Hardware:
Sonoff CC2531 USB stick coordinator zStack 1.2, rev. 20180507, channel: 11
MiJia door sensor MCCGQ01LM

/***************************  mijia.things  ****************************/
Bridge mqtt:broker:644a0a87 [ host="localhost", secure=true, username="openhab", password="12345" ]
{
    Thing topic MijiaDoorSensor "MiJia door contact sensor"  @ "Hall"
    { Channels:
            Type contact  : status      "status"      [ stateTopic = "zigbee2mqtt/mijiacontactsensor/contact", on="false", off="true" ]
            Type number   : voltage     "voltage"     [ stateTopic = "zigbee2mqtt/mijiacontactsensor/voltage" ]
            Type number   : battery     "battery"     [ stateTopic = "zigbee2mqtt/mijiacontactsensor/battery" ]
            Type number   : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/mijiacontactsensor/linkquality" ]
            Type datetime : last_change "last change" [ stateTopic = "zigbee2mqtt/mijiacontactsensor/last_seen" ]     
    }
}

/*******************  mijia.items  ****************************/
Contact  door_window_sensor_isOpen    "open status" <door>  {channel="mqtt:topic:644a0a87:MijiaDoorSensor:status"}
Number   door_window_sensor_VOLTAGE   "voltage [%d mV]"     {channel="mqtt:topic:644a0a87:MijiaDoorSensor:voltage"}
Number   door_window_sensor_BATTERY   "battery [%1.0f %%]" <battery>  {channel="mqtt:topic:644a0a87:MijiaDoorSensor:battery"}
Number   door_window_sensor_LINKQUALITY "link qualitiy [%d]" <qualityofservice> {channel="mqtt:topic:644a0a87:MijiaDoorSensor:linkquality"}
DateTime door_window_sensor_last_change "last change [%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS]" <calendar> {channel="mqtt:topic:644a0a87:MijiaDoorSensor:last_change"}

configuration.yaml

homeassistant: false
mqtt:
  base_topic: zigbee2mqtt
  password: 12345
  server: 'mqtt://127.0.0.1:1883'
  user: openhab
permit_join: false
serial:
  disable_led: true
  port: /dev/ttyACM0
devices:
  '0x00158d00027cff67':
    friendly_name: mijiacontactsensor
    retain: false
advanced:
  last_seen: ISO_8601_local
experimental:
  output: attribute
#\n\nadvanced:\n    network_key: GENERATE

/etc/systemd/system/zigbee2mqtt.service

[Unit]
Description=zigbee2mqtt
After=network.target

[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=openhab

[Install]
WantedBy=multi-user.target

What am I missing? Every hour I see a new meaning in the interface. Nobody opens the door. I open and then close the door and everything is correctly displayed in the openHAB, but exactly one hour later there is a change in the time. I left the terminal open and this comes from the broker. retain: false or retain: true - no difference.

screen

Thanks in advance for the help.

The topic is last_seen, not last change. Most wireless devices periodically report.
You can use openHABs timestamp profile to create a “last change” Item.

2 Likes

Thanks for the guidance rossko57, but I don’t know how to proceed. Where to edit exactly.

If you are not interested in the devices last_seen message, ignore it. Delete the link on your Item, remove the unwanted MQTT channel.
Now find out how to link the contact channel to your “Last Change” Item using a profile of type timestamp.

1 Like

I understood You.

Channel last_change out.
Item door_window_sensor_last_change out too.

In configuration.yaml
last_seen: ‘disable’.

And new quest with rule by name like lastChange.rules

rule "Mijia front door sensor"   
 when
   item door_window_sensor_isOpen changed
 then ....

Thank You again.

I found a practical solution to the problem in Sebastian’s answer here. It works as I expected.