How to know a sensor is powered on?

Hi - total newbie here - please be gentle. I have an Adafruit Huzzah feather ESP8266 with a magnetic door sensor connected. I already have it set up with MQTT PubSub so in node-red I can get the current state, or publish changes of state (open/closed), but on my Home Assistant dashboard, it shows the last state, not if it is powered on or off. Whats the best way to know through Home Assistant / Node-red if it is on or off and trigger an event when that changes? Thanks!

What topics are you publishing to MQTT?
Are you only posting the open/closed state?
You could post every x minutes or seconds an ‘online’ topic and have HA check to see how long it has been since last post to determine if it is up or not.

I’ve only set it to publish when there’s a change of state (eg closed to open), If I end up powering it with a battery pack I wasn’t sure if frequent posts would run down the batter faster. How do you set up a timer like that to show how long ago an event happend and display it in a dashboard element?