@dominictauscher
I followed your steps and everything seems to be fine when the sensor starts up. (used your second script)
Right after the startup I can see it in home assistant and when I fiddle with the tamper button it goes on/off in HA.
Now once it goes into sleep it goes completely offline (which is expected), but when I press the tamper button it does not wake up to report the new state. Is this the normal behavior?
My expectations were that it would wake up when I push the tamper button and it makes me wonder whether it will behave the same when smoke will be detected.
p.s.: appreciate your efforts and willingness to share it. Kudos, man!
L.E.:
I got it figured out eventually. It will wake up from sleep when smoke is detected and it will ring the alarm and go online to report, but it will not wake up when tampered.
The tampered sensor will only report back if it it happens to be "on" when the current sleep cycle ends. If this happens, then it will keep the sensor online for as long the tamper sensor is "on" or it runs out of battery.
Given that I don't install it in a rented property I don't care that much about the tamper function so I can let it sleep for one day at a time.
L.E.2:
Made some small adjustments to the script so that it measures the battery once every 60s.
Then at boot it will first check for smoke (in a loop) and if no smoke is detected then it will check to see if the device is tampered.
If the device is not tampered then it will enter in a ~36 hours (max) deep sleep to preserve battery.
However if the device is tampered, then it will enter in a 60 minutes deep sleep. This will basically put the device in a 60 minutes (reboot) loop reporting the (tampered) state every hour until someone fixes the issue. Of course that each reboot will also redo the whole initialization and check for smoke, but there's no harm in that.
I think this script will get the most out of the battery while still reporting the tampering state once an hour.
WARNING: if no smoke is detected, but the device is tampered you only have 5 minutes to adjust the script at boot before it goes back again in deep sleep for one hour. Only way to bring it back online is to remove the batteries and put them back on, giving you 5 more minutes of uptime.
Battery_Setup 1500 3000 2 2400 4096
//measure batt every 60s
Battery_cycle 60
//mqtt_broadcastInterval 1
//mqtt_broadcastItemsPerSec 5
addEventHandler OnHold 10 SafeMode 5
setChannelLabel 1 Smoke
setChannelLabel 2 Tamper
setChannelLabel 4 BatADC
setChannelLabel 5 BatRelay
// now wait for MQTT
waitFor MQTTState 1
// extra delay, to be sure
delay_s 1
// publish smoke and tamper state at least once after boot
publish 1 $CH1
publish 2 $CH2
publish 4 $CH4
publish 5 $CH5
// ------------------------------------------------
// if smoke detected, keep cycling (but drains battery)
again:
delay_s 2
if $CH1!=1 then goto again
delay_s 10
// at this point there's no smoke so if the device is not tampered, then go to 36 hours deep sleep
if $CH2==1 then goto dpsleep
// if tampered, keep rebooting once an hour to report (tampered) state
// the 300s delay window is for maintenance work
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 30
if $CH2==1 then goto dpsleep
delay_s 300
if $CH2==1 then goto dpsleep
PinDeepSleep 21600
dpsleep:
// All good, sleep for as long as possible (36 hours) to preserve battery
PinDeepSleep 130000
delay_s 3
// nothing