battery powered sensor

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
agroszer
Normal user
Posts: 28
Joined: 02 Jan 2023, 16:36

battery powered sensor

#1 Post by agroszer » 23 Oct 2023, 09:11

Hi,

I'm trying to get the best availability time for my battery powered sensor.
I'm good with power usage in deepsleep.
Will set static IP to reduce traffic and wake time.

What else can I do to reduce wake time (and power usage)?

Data submission is done with a rule:

Code: Select all

"On MQTT#Connected Do //when the broker is connected
  If [sleepenabled#State]=1
    taskrun,1 // run and send to MQTT
    taskrun,2 // run and send to MQTT
    // deepsleep,300 //go to deepsleep
    timerSet,1,1
  EndIf
EndOn

On Rules#Timer=1 Do
  deepsleep,300 //go to deepsleep
EndOn
thank you

agroszer
Normal user
Posts: 28
Joined: 02 Jan 2023, 16:36

Re: battery powered sensor

#2 Post by agroszer » 23 Oct 2023, 09:22

Another interesting question is, taskrun MQTT publish seems to run queued, if I do deepsleep right after taskrun nothing gets published.
Does publish also run queued or it waits and the next command is execute only on success?

I might do better with disabling report to controller on the device and doing:

Code: Select all

On MQTT#Connected Do //when the broker is connected
  If [sleepenabled#State]=1
    taskrun,1 // run
    publish homeassistant/esp_01_3/bojler/Temperature,[bojler#Temperature]
    deepsleep,300 //go to deepsleep
  EndIf
EndOn

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: battery powered sensor

#3 Post by chromo23 » 23 Oct 2023, 10:15

agroszer wrote: 23 Oct 2023, 09:11 What else can I do to reduce wake time (and power usage)?
I can show you how my code works to reduce uptime when reading a sensor and sending its data to thingspeak.
Basically i wait for WiFi and sensordata to become available and send it to thingspeak.
I don't use the sleep options in the /config tab. I emulate therefore the "30seconds after reboot" behavior in rules
If the data is send successfully go to sleep immediately....

Code: Select all

On System#Wake Do
  LoopTimerSet_ms,1,100,50 //loop until wifi is connected and we got data from sensor
  GPIO,12,1			   //Turn on the sensor
  TaskRun,1 	                  // Update first sensor
Endon

On WiFi#Connected Do
  Let,1,1
Endon

On sensor_extern#All Do
  Let,2,1
Endon 

On Rules#Timer=1 Do
   If [var#1]=1 and [var#2]=1	//when wifi is connected and there are values from the sensor send data
	 SendToHTTP api.thingspeak.com,80,/update?api_key=XXXXXXXXXXXXX&field8=[batterie#Analog]&field4=[sensor_extern#Humidity]&field7=[sensor_extern#Pressure]&field3=[sensor_extern#Temperature]	 	
 	 TimerSet_ms,1,0
 	 Let,1,0
	 Let,2,0
  Elseif %eventvalue2%=50        //after 5sec go back to sleep
	Event,sleep 
  Endif
Endon

On http#api.thingspeak.com=200 Do    //when receiving the HTTP code 200 it basically means the sending was successful
  Event,sleep
Endon

On sleep Do    //after sending data either go to sleep or if power cycled wait 30sec
  If [boot#isboot]=1
	DeepSleep,1800 //comment this out to stop deepsleep
  Else
	TimerSet,2,30
	TaskValueSet,boot,1,1    //this sets the first value of a dummy device called boot to 1 
    //it doesn´t survive a reboot and therefore becomes 0. so you have 30 seconds after a reboot to do changes 
  Endif
Endon

On Rules#Timer=2 Do
  Event,sleep
Endon

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: battery powered sensor

#4 Post by TD-er » 23 Oct 2023, 11:12

Apart from the rules, you may also want to look at the electronics.
Most voltage regulators used have a high quiescent current usage.
Meaning they even draw a few mA when not powering anything (or very little power demand)

Also you may want to put some FETs to be able to switch on/off some sensors and connect them to an ESP pin you then pull high on the hardware tab at boot.

agroszer
Normal user
Posts: 28
Joined: 02 Jan 2023, 16:36

Re: battery powered sensor

#5 Post by agroszer » 29 Oct 2023, 18:57

Yeah, I connected an ESP12F directly to 3xAA NiMH batteries. ESP is happy with the ~4.2V input. I have an SHT20, powered on demand with a FET (power pin is set with hardware/defaults) and a DS18b20 always powered it does not seem to consume much idle. Both devices do NOT publish data to the controller.

Current rule is below, I'll try to reduce TimerSet_ms,1,150 or get rid of it as next.

Code: Select all

// failsafe:
// if no wifi or no mqtt or whatever go back to sleep after 30 secs
// 30 secs should be more than enough to connect and send via mqtt
On System#Boot Do
  timerSet,1,30
  taskrun,1 // just run do NOT send
  taskrun,2 // just run do NOT send
EndOn


On MQTT#Connected Do //when the broker is connected
  If [sleepenabled#State]=1
    publish,homeassistant/esp_01_3/room/Temperature,[room#Temperature]
    publish,homeassistant/esp_01_3/room/Humidity,[room#Humidity]
    publish,homeassistant/esp_01_3/bojler/Temperature,[bojler#Temperature]

    TimerSet_ms,1,150
  EndIf
EndOn

On Rules#Timer=1 Do
  If [sleepenabled#State]=1
    deepsleep,300 //go to deepsleep
  EndIf
EndOn

Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests