Integromat project function call

How to call the trigger function when sensor value give awkward value??

Hi @pratapkumarshu21,

Can you please elaborate more on the issue you are facing by providing code, necessary screenshots and all the relevant data so that we can help you out.

To trigger a function when a sensor value gives an unusual or unexpected reading when working with a Bolt WiFi module, you can implement conditional statements in your code to check the sensor value.
Here how you can do it,
Use conditional statements (e.g., if statements) to check if the sensor value falls outside the defined thresholds. If the value is beyond the threshold, trigger the desired function. Here’s a simplified example in Python for a temperature sensor:

import boltiot
import json

threshold = 40 # Set the threshold value

myBolt = boltiot.Bolt(API_KEY, DEVICE_ID)

while True:
response = myBolt.analogRead(‘A0’) # Read temperature sensor data from analog pin A0
data = json.loads(response)

if data['value'] > threshold:
    # Trigger the function or take action for an unusual value
    print("Unusual temperature value detected:", data['value'])
    # Call your function or execute the necessary actions here


This is my code. Cant understand the fault. When LDR senses some higher intensity light then its not posting any post in my facebook page.

@pratapkumarshu21,

import conf3
import time
import math
import statistics
import requests
import json
from boltiot import Bolt

mybolt = Bolt(conf3.API_KEY, conf3.DEVICE_ID)

history_data = []

def compute_bounds(history_data, frame_size, factor):
    if len(history_data) < frame_size:
        return None

    if len(history_data) > frame_size:
        del history_data[0: len(history_data) - frame_size]

    Mn = statistics.mean(history_data)
    Variance = 0

    for data in history_data:
        Variance += math.pow((data - Mn), 2)

    Zn = factor * math.sqrt(Variance / frame_size)

    high_bound = history_data[frame_size - 1] + Zn
    low_bound = history_data[frame_size - 1] - Zn

    return [high_bound, low_bound]

def trigger_integromat_webhook():
    URL = "https://hook.us1.make.com"
    response = requests.request("GET", URL)
    print(response.text)

while True:
    response = mybolt.analogRead("A")
    data = json.loads(response)

    if data['success'] != 1:
        print("There was an error while retrieving the data.")
        print("This is the error:", data['value'])
        time.sleep(10)
        continue

    print("This is the value:", data['value'])
    sensor_value = 0

    try:
        sensor_value = int(data['value'])
    except Exception as e:
        print("There was an error while parsing the response:", e)
        continue

    bound = compute_bounds(history_data, conf3.FRAME_SIZE, conf3.MUL_FACTOR)
    
    if not bound:
        required_data_count = conf3.FRAME_SIZE - len(history_data)
        print("Not enough data to compute Z-score. Need", required_data_count, "more data points")
        history_data.append(sensor_value)
        time.sleep(10)
        continue

    try:
        if sensor_value > bound[0]:
            print("The light level increased suddenly. Sending a post.")
            trigger_integromat_webhook()
            print("This is the response:", response)
        elif sensor_value < bound[1]:
            print("The light level decreased suddenly. Sending a post.")
            trigger_integromat_webhook()
            print("This is the response:", response)
        history_data.append(sensor_value)
    except Exception as e:
        print("Error:", e)
    time.sleep(10)

Your code appears to be an anomaly detection system that triggers actions based on light intensity readings from an LDR.

  • Your code doesn’t currently contain any logic related to posting on Facebook. To post on Facebook, you need to use the Facebook API or an appropriate method to trigger the desired action on your Facebook page.
  • Ensure that your trigger conditions based on light levels are appropriately set for the desired actions. You might need to adjust the threshold values based on your specific requirements.

Without specific details about how you intend to post on Facebook and what conditions trigger the posting, it’s challenging to provide a complete solution. If you have Facebook posting code that you haven’t included here, please share that as well.