Data is not recorded as what expected to be

Hi all,
I’m a beginner to InfluxDB, while I was working with my project, I was using Thonny to implement my code to my Raspberry Pi 4B, everything is fine in Thonny, and I’m using NODE-RED to get the digital outputs from sensors(PIR motion sensor, sound sensor, ir sensor, and ldr sensor) and write the measurements to influxdb with only one field and one tag. Then, InfluxDB IS displaying the output captured with the sensor, but not the way I expected, the field and tags are replicated. Here’s what I got:

My expected output should be no location_1, all the readings from the sensor should be true/false and recorded in the motion_detected instead of 0/1, anyone have any suggestions to get rid of this?

Also, my NODE-RED flows (Note: I’m trying a change node on the motion sensor, and once the bug is fixed i can move on to the next sensor, same goes to the the remaining four influx in nodes as well):

[
    {
        "id": "060d697982724369",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "7780151f8ace4021",
        "type": "ui_text",
        "z": "060d697982724369",
        "group": "36a6e50b14fe6986",
        "order": 1,
        "width": 8,
        "height": 3,
        "name": "",
        "label": "Living Room ",
        "format": "{{msg.payload}}",
        "layout": "col-center",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 590,
        "y": 300,
        "wires": []
    },
    {
        "id": "253102458ccd7068",
        "type": "ui_text",
        "z": "060d697982724369",
        "group": "36a6e50b14fe6986",
        "order": 2,
        "width": 8,
        "height": 3,
        "name": "",
        "label": "Kitchen ",
        "format": "{{msg.payload}}",
        "layout": "col-center",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 580,
        "y": 360,
        "wires": []
    },
    {
        "id": "263a823485057346",
        "type": "ui_text",
        "z": "060d697982724369",
        "group": "36a6e50b14fe6986",
        "order": 3,
        "width": 8,
        "height": 3,
        "name": "",
        "label": "Dining Room",
        "format": "{{msg.payload}}",
        "layout": "col-center",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 590,
        "y": 420,
        "wires": []
    },
    {
        "id": "33897ee58ff43341",
        "type": "ui_text",
        "z": "060d697982724369",
        "group": "36a6e50b14fe6986",
        "order": 4,
        "width": 8,
        "height": 3,
        "name": "",
        "label": "Study Room",
        "format": "{{msg.payload}}",
        "layout": "col-center",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 590,
        "y": 480,
        "wires": []
    },
    {
        "id": "92dc232103c05f59",
        "type": "function",
        "z": "060d697982724369",
        "name": "Active/Inactive",
        "func": "if (msg.payload === 'active') {\n    msg.payload = 'Active';\n    msg.color = 'green'; // Set the color to green for active\n} else {\n    msg.payload = 'Inactive';\n    msg.color = 'red'; // Set the color to red for inactive\n}\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 400,
        "wires": [
            [
                "7780151f8ace4021",
                "253102458ccd7068",
                "263a823485057346",
                "33897ee58ff43341"
            ]
        ]
    },
    {
        "id": "fa7371ce071f2d7d",
        "type": "mqtt out",
        "z": "060d697982724369",
        "name": "Living Room",
        "topic": "living_room",
        "qos": "0",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "e67aa097c74b5b68",
        "x": 270,
        "y": 40,
        "wires": []
    },
    {
        "id": "4c9319562bede7b5",
        "type": "mqtt out",
        "z": "060d697982724369",
        "name": "Kitchen",
        "topic": "kitchen",
        "qos": "0",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "e67aa097c74b5b68",
        "x": 260,
        "y": 100,
        "wires": []
    },
    {
        "id": "bdc8bf319c89dc12",
        "type": "mqtt out",
        "z": "060d697982724369",
        "name": "Dining Room",
        "topic": "dining_room",
        "qos": "0",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "e67aa097c74b5b68",
        "x": 270,
        "y": 160,
        "wires": []
    },
    {
        "id": "e8f7886469417dc2",
        "type": "mqtt out",
        "z": "060d697982724369",
        "name": "Study Room",
        "topic": "study_room",
        "qos": "0",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "e67aa097c74b5b68",
        "x": 270,
        "y": 220,
        "wires": []
    },
    {
        "id": "5c719666cb31bcc5",
        "type": "mqtt in",
        "z": "060d697982724369",
        "name": "Living Room",
        "topic": "living_room",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "e67aa097c74b5b68",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 430,
        "y": 40,
        "wires": [
            [
                "a96846dc0bac5b41"
            ]
        ]
    },
    {
        "id": "543e1e5b98d2b715",
        "type": "mqtt in",
        "z": "060d697982724369",
        "name": "Kitchen",
        "topic": "kitchen",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "e67aa097c74b5b68",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 410,
        "y": 100,
        "wires": [
            [
                "977e60a195869ff3"
            ]
        ]
    },
    {
        "id": "69561480529c151a",
        "type": "mqtt in",
        "z": "060d697982724369",
        "name": "Dining Room",
        "topic": "dining_room",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "e67aa097c74b5b68",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 430,
        "y": 160,
        "wires": [
            [
                "69571638ac54c6c7"
            ]
        ]
    },
    {
        "id": "b12082f6b45be981",
        "type": "mqtt in",
        "z": "060d697982724369",
        "name": "Study Room",
        "topic": "study_room",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "e67aa097c74b5b68",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 430,
        "y": 220,
        "wires": [
            [
                "fe1af75822b97fb8"
            ]
        ]
    },
    {
        "id": "eb43832ab4839ca5",
        "type": "influxdb out",
        "z": "060d697982724369",
        "influxdb": "c2ff6d0aa9002837",
        "name": "Motion Sensor",
        "measurement": "motion",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 800,
        "y": 40,
        "wires": []
    },
    {
        "id": "977e60a195869ff3",
        "type": "influxdb out",
        "z": "060d697982724369",
        "influxdb": "c2ff6d0aa9002837",
        "name": "Sound Sensor",
        "measurement": "sound",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 800,
        "y": 100,
        "wires": []
    },
    {
        "id": "69571638ac54c6c7",
        "type": "influxdb out",
        "z": "060d697982724369",
        "influxdb": "c2ff6d0aa9002837",
        "name": "IR Sensor",
        "measurement": "infrared",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 780,
        "y": 160,
        "wires": []
    },
    {
        "id": "fe1af75822b97fb8",
        "type": "influxdb out",
        "z": "060d697982724369",
        "influxdb": "c2ff6d0aa9002837",
        "name": "LDR Sensor",
        "measurement": "ldr",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 790,
        "y": 220,
        "wires": []
    },
    {
        "id": "b060f2bd420899fb",
        "type": "influxdb in",
        "z": "060d697982724369",
        "influxdb": "c2ff6d0aa9002837",
        "name": "Motion Sensor",
        "query": "select * from motion",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 120,
        "y": 340,
        "wires": [
            [
                "92dc232103c05f59"
            ]
        ]
    },
    {
        "id": "3064fe40f5ceaf5c",
        "type": "influxdb in",
        "z": "060d697982724369",
        "influxdb": "c2ff6d0aa9002837",
        "name": "Sound Sensor",
        "query": "select * from sound",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 120,
        "y": 380,
        "wires": [
            [
                "92dc232103c05f59"
            ]
        ]
    },
    {
        "id": "b668cd3e1ce32ee5",
        "type": "influxdb in",
        "z": "060d697982724369",
        "influxdb": "c2ff6d0aa9002837",
        "name": "IR Sensor",
        "query": "select * from infrared",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 100,
        "y": 420,
        "wires": [
            [
                "92dc232103c05f59"
            ]
        ]
    },
    {
        "id": "30b4c4e68dfb027f",
        "type": "influxdb in",
        "z": "060d697982724369",
        "influxdb": "c2ff6d0aa9002837",
        "name": "LDR Sensor",
        "query": "select * from ldr",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 110,
        "y": 460,
        "wires": [
            [
                "92dc232103c05f59"
            ]
        ]
    },
    {
        "id": "dc4a873ab6d60571",
        "type": "rpi-gpio in",
        "z": "060d697982724369",
        "name": "Motion Sensor",
        "pin": "17",
        "intype": "tri",
        "debounce": "25",
        "read": false,
        "bcm": true,
        "x": 90,
        "y": 40,
        "wires": [
            [
                "fa7371ce071f2d7d"
            ]
        ]
    },
    {
        "id": "2e2033e46df3e3fc",
        "type": "rpi-gpio in",
        "z": "060d697982724369",
        "name": "Voice Sensor",
        "pin": "27",
        "intype": "tri",
        "debounce": "25",
        "read": false,
        "bcm": true,
        "x": 90,
        "y": 100,
        "wires": [
            [
                "4c9319562bede7b5"
            ]
        ]
    },
    {
        "id": "f2fd76fd2d4f0e61",
        "type": "rpi-gpio in",
        "z": "060d697982724369",
        "name": "IR Sensor",
        "pin": "22",
        "intype": "tri",
        "debounce": "25",
        "read": false,
        "bcm": true,
        "x": 80,
        "y": 160,
        "wires": [
            [
                "bdc8bf319c89dc12"
            ]
        ]
    },
    {
        "id": "a8ed18964b090733",
        "type": "rpi-gpio in",
        "z": "060d697982724369",
        "name": "LDR Sensor",
        "pin": "23",
        "intype": "tri",
        "debounce": "25",
        "read": false,
        "bcm": true,
        "x": 90,
        "y": 220,
        "wires": [
            [
                "e8f7886469417dc2"
            ]
        ]
    },
    {
        "id": "a96846dc0bac5b41",
        "type": "change",
        "z": "060d697982724369",
        "name": "Motion Sensor",
        "rules": [
            {
                "t": "set",
                "p": "fields.location",
                "pt": "msg",
                "to": "living",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "tags.motion_detected",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$append(fields,tags)",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 600,
        "y": 40,
        "wires": [
            [
                "eb43832ab4839ca5"
            ]
        ]
    },
    {
        "id": "36a6e50b14fe6986",
        "type": "ui_group",
        "name": "Smart Home Energy Optimization",
        "tab": "33dbc667cffcae0b",
        "order": 1,
        "disp": true,
        "width": "16",
        "collapse": false,
        "className": ""
    },
    {
        "id": "e67aa097c74b5b68",
        "type": "mqtt-broker",
        "name": "",
        "broker": "broker.emqx.io",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "c2ff6d0aa9002837",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "SHEMS",
        "name": "SHEMS",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://localhost:8086",
        "rejectUnauthorized": true
    },
    {
        "id": "33dbc667cffcae0b",
        "type": "ui_tab",
        "name": "SHEMS",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

And Thonny’s:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

def read_sensor_data():
    pir_sensor = 17
    voice_sensor = 27
    ir_sensor = 22
    ldr_sensor = 23

    GPIO.setup(pir_sensor, GPIO.IN)
    GPIO.setup(voice_sensor, GPIO.IN)
    GPIO.setup(ir_sensor, GPIO.IN)
    GPIO.setup(ldr_sensor, GPIO.IN)

    pir_state = GPIO.input(pir_sensor)
    voice_state = GPIO.input(voice_sensor)
    ir_state = GPIO.input(ir_sensor)
    ldr_state = GPIO.input(ldr_sensor)

    return pir_state, voice_state, ir_state, ldr_state


redLED_living = 2
greenLED_kitchen = 3
whiteLED_dining = 4
blueLED_study = 15

GPIO.setup(redLED_living, GPIO.OUT)
GPIO.setup(greenLED_kitchen, GPIO.OUT)
GPIO.setup(whiteLED_dining, GPIO.OUT)
GPIO.setup(blueLED_study, GPIO.OUT)

try:
    while True:
        pir_state, voice_state, ir_state, ldr_state = read_sensor_data()

        if ldr_state == GPIO.LOW:
            GPIO.output(blueLED_study, GPIO.HIGH)
            print("Light Detected! Turning on study room lights.")
        else:
            GPIO.output(blueLED_study, GPIO.LOW)
            print("No light detected. Turning off study room lights.")

        if pir_state == GPIO.HIGH:
            GPIO.output(redLED_living, GPIO.HIGH)
            print("Motion Detected! Turning on living room lights.")
        else:
            GPIO.output(redLED_living, GPIO.LOW)
            print("No motion detected. Turning off living room lights.")

        if ir_state == GPIO.HIGH:
            GPIO.output(whiteLED_dining, GPIO.LOW)
            print("No Presence Detected. Turning off dining room lights.")
        else:
            GPIO.output(whiteLED_dining, GPIO.HIGH)
            print("Presence detected! Turning on dining room lights.")

        if voice_state == GPIO.HIGH:
            GPIO.output(greenLED_kitchen, GPIO.HIGH)
            print("Voice Detected! Turning on kitchen lights.")
        else:
            GPIO.output(greenLED_kitchen, GPIO.LOW)
            print("No voice detected. Turning off kitchen lights.")

        time.sleep(1)
        print("\n")

except KeyboardInterrupt:
    print("\nExiting Program")
    GPIO.cleanup()

Edit: I figured out just by dropping the measurement in InfluxCLI, and deploying again in NODE-RED, no replication of another field(location_1 & motion_detected_1 again), however, i kinda want it to display false when the digital output is low, still figuring out how

EDIT: Nevermind i solved it by using the $boolean(msg.payload = 0 ? false : true) in the NODE-RED change node. Problem solved.