HA with nodemcu door sensor

Hello… I want a mqtt door sensor. Been playing with a few that are already made for a nodemcu. Each one Ive been experimenting with has its own “bugs”. The latest one that Im using is below. I applied the fixed as outlined in the comments. For some reason if the door is open or closed the update is always a 2 ( see mqtt log below) . What is going on?

1554514817: |-- mosquitto_auth_acl_check(…, client id not available, you, sensor/doorbell/door-status, MOSQ_ACL_WRITE)
1554514817: |-- aclcheck(you, sensor/doorbell/door-status, 2) CACHEDAUTH: 0
1554514831: |-- mosquitto_auth_acl_check(…, client id not available, you, sensor/doorbell/door-status, MOSQ_ACL_WRITE)
1554514831: |-- aclcheck(you, sensor/doorbell/door-status, 2) CACHEDAUTH: 0