Hi Haruto,
No problems, there are many ways how you can do that so I will give you one example.
I don't know if you need to be able to change 20% limit through Actions or is it something you can hardcode on the device?
This example is if you can hardcode the 20% limit on the device
1. first in the Dev Console add an extra "ON/OFF" component to your device and call it something like "alert"
2. make the Action so it triggers a notification when the new "alert" component is "ON" - we are not going to be checking in the Actions what the sensor reading is but rather if the "alert" component is "ON"
3. read the comments I have included in the code below
int alert_limit = 20; // this is the 20% limit that will trigger a notification
bool alert_blocked = false; // we will use this to trigger a notification and then stop it from happening again
unsigned long last_alert_time = 0; // we will use this to track the time
void setup(){
... do what you need to do here
}
void loop(){
int sensor_value = sensor.read(); // do some sensor reading
if(sensor_value < alert_limit){ // we are below the allowed limit
if(alert_blocked == false){ // if alert is not blocked then we tell ChipChop otherwise we do nothing
ChipChop.triggerEvent("alert","ON"); //send this immediately and it will trigger the Action
ChipChop.updateStatus("alert","OFF"); // <<< IMPORTANT: reset the alert component straight away so it doesn't trigger the notification on the next heartbeat
alert_blocked = true; // prevent future alerts
last_alert_time = millis(); // start a timer
}
}
// if we have blocked the alert, check when 1 hour has passed and reset it so we can send alerts again
if(alert_blocked == true){
if(millis() - last_alert_time >= 3600000)){ // when 1 hour is passed, allow new alerts
alert_blocked = false; // unblock the alerts
}
}
}
It's a little bit more complicated if you need to dynamically change the 20% limit through the Action, what I mean is if today you use less than 20% but tomorrow you change your mind and want the notification to be triggered when it's below 30%
It can be done in many ways and normally I would use LittleFS to save on the device the 20% limit as a settings value in the flash memory and then remotely update the value if I want and read it from flash every time the device restarts.
Let me know if you need this option and I will make you some more code but you would have to use the Code Builder in the Dev Console to generate the initial code template (it's easier for ESP32 using the Code Builder and the Prefs Manager plugin)
I have increased the notifications limit on your account so you don't run out whilst you are experimenting :-)
I hope this helps and let me know if you manage to get it working
Gizmo