# Ghost Thermostat:Cant retain Target temp and state, reverts to defaulted values i cant seem to locate

**URL:** <https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765>\
**Category:** General\
**Tags:** node-red-dashboard, function-node\
**Created:** [10 November 2023 18:26 UTC](https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765 "2023-11-10T18:26:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Automata](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@Automata](https://discourse.nodered.org/u/Automata)\
**Post date:** [10 November 2023 18:26 UTC](https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765/1 "2023-11-10T18:26:52Z")

</div>

update: mqqt bme280 in is working. but still have the stat reverting to a defaulted value. flow/code attached this time.

```auto
[
    {
        "id": "c69f4c874a69e46a",
        "type": "ui_ui_control",
        "z": "1fef5af48987e862",
        "name": "",
        "events": "all",
        "x": 3340,
        "y": 820,
        "wires": [
            [
                "441ee3605ebe21e9",
                "70892cf3a2425e65"
            ]
        ]
    },
    {
        "id": "0db49073c80b4848",
        "type": "function",
        "z": "1fef5af48987e862",
        "name": "target_temperature",
        "func": "msg.topic = 'target_temperature';\nvar data = {\n 'target_temperature':msg.payload \n}\nmsg.payload = data;\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 2550,
        "y": 860,
        "wires": [
            [
                "b970206bd9e41276",
                "a03c9f54bdd84880"
            ]
        ]
    },
    {
        "id": "a0751344b25431c5",
        "type": "function",
        "z": "1fef5af48987e862",
        "name": "hvac_state",
        "func": "msg.topic = \"hvac_state\";\nglobal.set(\"hvac_state\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 2730,
        "y": 1180,
        "wires": [
            [
                "a03c9f54bdd84880",
                "8361cfb7b1422492"
            ]
        ]
    },
    {
        "id": "21089888fd1ad681",
        "type": "function",
        "z": "1fef5af48987e862",
        "name": "away",
        "func": "msg.topic = \"away\";\nglobal.set(\"away\", msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 2750,
        "y": 1220,
        "wires": [
            [
                "3679633df92d935f",
                "532c26de0efbdd5d",
                "789023cb7db45a79",
                "3a25b47ef744f5ed"
            ]
        ]
    },
    {
        "id": "a03c9f54bdd84880",
        "type": "function",
        "z": "1fef5af48987e862",
        "name": "Data",
        "func": "\nif (msg.topic == \"ambient_temperature\") {\n global.set(\"ambient_temperature\", msg.payload.ambient_temperature);\n}\nmsg.topic = \"update\";\nvar data = {\n 'ambient_temperature': global.get(\"ambient_temperature\") || 72,\n 'target_temperature': global.get(\"target_temperature\") || 72,\n 'hvac_state': global.get(\"hvac_state\") || 'off',\n 'away': global.get(\"away\") || 'false'\n}\nmsg.payload = data;\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 2990,
        "y": 1060,
        "wires": [
            [
                "71daca0a0035395d",
                "441ee3605ebe21e9"
            ]
        ]
    },
    {
        "id": "8361cfb7b1422492",
        "type": "debug",
        "z": "1fef5af48987e862",
        "name": "debug 19",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 2720,
        "y": 1140,
        "wires": []
    },
    {
        "id": "b970206bd9e41276",
        "type": "debug",
        "z": "1fef5af48987e862",
        "d": true,
        "name": "debug 21",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 2560,
        "y": 820,
        "wires": []
    },
    {
        "id": "71daca0a0035395d",
        "type": "debug",
        "z": "1fef5af48987e862",
        "name": "debug 22",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 3040,
        "y": 960,
        "wires": []
    },
    {
        "id": "70892cf3a2425e65",
        "type": "debug",
        "z": "1fef5af48987e862",
        "name": "debug 24",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 3340,
        "y": 780,
        "wires": []
    },
    {
        "id": "532c26de0efbdd5d",
        "type": "debug",
        "z": "1fef5af48987e862",
        "name": "debug 41",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 3000,
        "y": 1220,
        "wires": []
    },
    {
        "id": "789023cb7db45a79",
        "type": "change",
        "z": "1fef5af48987e862",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "true",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2940,
        "y": 1180,
        "wires": [
            [
                "a03c9f54bdd84880"
            ]
        ]
    }
]

```

Good afternoon all, i have my flow operational and accepts all my data inputs and thermostat responds correctly turning on my pi relays. The issue im facing and can not seem to track down is that the stat reverts to 72\* and "OFF" after about 30 seconds after changing via UI . debug changes to everything correctly until it reverts. i have debug nodes attached throughout. any help greatly appreciated. im still a new forum user so cant upload my flow.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 November 2023 21:13 UTC](https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765/2 "2023-11-10T21:13:35Z")

</div>

I've updated your permission so you should be able to upload a flow.

BUT before you do, please create a small flow showing the issue and provide some more information

- what version of NR an anode.js? (see NR startup log)
- what device are you running NR on?

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [11 November 2023 00:26 UTC](https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765/3 "2023-11-11T00:26:53Z")

</div>

It sounds like you are sending something to it every 30 seconds ?

Its a while since I set it up, but it may help if you send all values at once -

eg `{ 'ambient_temperature': xx , 'target_temperature':xx , 'mode': "OFF" , 'away': 'false' }`

---

<div class="post-metadata">

**Author:** ![Automata](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@Automata](https://discourse.nodered.org/u/Automata)\
**Post date:** [11 November 2023 18:14 UTC](https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765/4 "2023-11-11T18:14:31Z")

</div>

what im trying to achieve is keeping the target temp set from UI until changed again from UI, same for Mode. but after i change them from UI, They revert to off and either a defaulted value of 72 because nothing is found, or a 68 if i manually inject. my ambient temp payload is in the same format being sent to a data function before the stat, and it is correct and stays. so im lost as to why the mode and target temp revert.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [11 November 2023 19:53 UTC](https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765/5 "2023-11-11T19:53:19Z")

</div>

You need to store the output from the stat, and then feed all values back in, even if you only what to change one of them, as the template doesn't remember the settings I don't think. So any missing values will likely switch to default.

i.e. As I showed in previous post, so put a function before the stat something like this -

```auto
var data = {
    'ambient_temperature': global.get("nest1_ambient_temperature") ,
    'target_temperature': global.get("nest1_target_temperature") ,
    'mode': global.get("heating_current_mode") || 'off',
    'away': global.get("nest1_away") || 'false'
}
msg.payload = data;

```

---

<div class="post-metadata">

**Author:** ![Automata](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@Automata](https://discourse.nodered.org/u/Automata)\
**Post date:** [11 November 2023 21:14 UTC](https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765/6 "2023-11-11T21:14:56Z")

</div>

> [@Sean-McG](#):
>
> ```auto
> var data = {
> 'ambient_temperature': global.get("nest1_ambient_temperature") ,
> 'target_temperature': global.get("nest1_target_temperature") ,
> 'mode': global.get("heating_current_mode") || 'off',
> 'away': global.get("nest1_away") || 'false'
> }
> msg.payload = data;
> 
> ```

i almost had this exact function, i was missing the "nest1 (ghostThermostat) in my case, i do not need it for the ambient temperature however. its all up and working at the moment. thank you so much for the guidance.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 November 2023 21:15 UTC](https://discourse.nodered.org/t/ghost-thermostat-cant-retain-target-temp-and-state-reverts-to-defaulted-values-i-cant-seem-to-locate/82765/7 "2023-11-25T21:15:40Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
