Need help debugging automation for reptile enclosure [solved]

I have an automation that manages the climate in a terrarium that is housing my fire skink. I recently consolidated multiple automations into one in an attempt to practice and reduce clutter. The automation itself is pretty simple but it’s not behaving as I would expect. When the sun rises or sets, it’s supposed to turn on or off the UV lamp and basking bulb. Instead it is setting off the humidity control sequence (which is disabled). Below is the trace for the latest execution. Any help would be greatly appreciated.

{
  "trace": {
    "last_step": "action/0/choose/2/sequence/2",
    "run_id": "6bb39a4a5fb54f2cabc0b9e2d0b3bb32",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-09-27T12:50:48.779617+00:00",
      "finish": "2023-09-27T12:52:48.822309+00:00"
    },
    "domain": "automation",
    "item_id": "1694293975312",
    "trigger": "state of sun.sun",
    "trace": {
      "trigger/3": [
        {
          "path": "trigger/3",
          "timestamp": "2023-09-27T12:50:48.779651+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.maintain_reptile_humidity",
              "state": "on",
              "attributes": {
                "id": "1694293975312",
                "last_triggered": "2023-09-27T00:52:05.114513+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Maintain skink climate"
              },
              "last_changed": "2023-09-26T14:39:45.155349+00:00",
              "last_updated": "2023-09-27T00:54:05.157509+00:00",
              "context": {
                "id": "01HBA21Y3557TNBHAKCJVZ94GH",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "sun",
              "idx": "3",
              "alias": null,
              "platform": "state",
              "entity_id": "sun.sun",
              "from_state": {
                "entity_id": "sun.sun",
                "state": "below_horizon",
                "attributes": {
                  "next_dawn": "2023-09-28T12:21:31.804251+00:00",
                  "next_dusk": "2023-09-28T01:18:38.114731+00:00",
                  "next_midnight": "2023-09-28T06:49:36+00:00",
                  "next_noon": "2023-09-27T18:50:13+00:00",
                  "next_rising": "2023-09-28T12:49:45.770045+00:00",
                  "next_setting": "2023-09-28T00:50:27.422718+00:00",
                  "elevation": -1.04,
                  "azimuth": 91.08,
                  "rising": true,
                  "friendly_name": "Sun"
                },
                "last_changed": "2023-09-27T00:52:05.112328+00:00",
                "last_updated": "2023-09-27T12:48:48.778198+00:00",
                "context": {
                  "id": "01HBBAYMMATZ19JWSQ7AZGPFRH",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "sun.sun",
                "state": "above_horizon",
                "attributes": {
                  "next_dawn": "2023-09-28T12:21:31.804251+00:00",
                  "next_dusk": "2023-09-28T01:18:38.114731+00:00",
                  "next_midnight": "2023-09-28T06:49:36+00:00",
                  "next_noon": "2023-09-27T18:50:13+00:00",
                  "next_rising": "2023-09-28T12:49:45.770045+00:00",
                  "next_setting": "2023-09-28T00:50:27.422718+00:00",
                  "elevation": -0.55,
                  "azimuth": 91.4,
                  "rising": true,
                  "friendly_name": "Sun"
                },
                "last_changed": "2023-09-27T12:50:48.779204+00:00",
                "last_updated": "2023-09-27T12:50:48.779204+00:00",
                "context": {
                  "id": "01HBBB29TB579JDQNAHM2WYFBB",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of sun.sun"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2023-09-27T12:50:48.779665+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "condition/0/conditions/0": [
        {
          "path": "condition/0/conditions/0",
          "timestamp": "2023-09-27T12:50:48.779673+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "condition/0/conditions/0/conditions/0": [
        {
          "path": "condition/0/conditions/0/conditions/0",
          "timestamp": "2023-09-27T12:50:48.779678+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "condition/0/conditions/1": [
        {
          "path": "condition/0/conditions/1",
          "timestamp": "2023-09-27T12:50:48.779691+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "condition/0/conditions/1/conditions/0": [
        {
          "path": "condition/0/conditions/1/conditions/0",
          "timestamp": "2023-09-27T12:50:48.779696+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-09-27T12:50:48.780189+00:00",
          "changed_variables": {
            "context": {
              "id": "01HBBB29TBB2CK6BM3RBTKT8XV",
              "parent_id": "01HBBB29TB579JDQNAHM2WYFBB",
              "user_id": null
            }
          },
          "result": {
            "choice": 2
          }
        }
      ],
      "action/0/choose/0": [
        {
          "path": "action/0/choose/0",
          "timestamp": "2023-09-27T12:50:48.780216+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0",
          "timestamp": "2023-09-27T12:50:48.780223+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1": [
        {
          "path": "action/0/choose/1",
          "timestamp": "2023-09-27T12:50:48.780237+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0": [
        {
          "path": "action/0/choose/1/conditions/0",
          "timestamp": "2023-09-27T12:50:48.780241+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/2": [
        {
          "path": "action/0/choose/2",
          "timestamp": "2023-09-27T12:50:48.780251+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/2/conditions/0": [
        {
          "path": "action/0/choose/2/conditions/0",
          "timestamp": "2023-09-27T12:50:48.780257+00:00",
          "result": {
            "result": null
          }
        }
      ],
      "action/0/choose/2/sequence/0": [
        {
          "path": "action/0/choose/2/sequence/0",
          "timestamp": "2023-09-27T12:50:48.780342+00:00",
          "result": {
            "params": {
              "domain": "switch",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "switch.tp_link_power_strip_8108_kasa_smart_plug_8108_0"
                ]
              }
            },
            "running_script": false
          }
        }
      ],
      "action/0/choose/2/sequence/1": [
        {
          "path": "action/0/choose/2/sequence/1",
          "timestamp": "2023-09-27T12:50:48.799549+00:00",
          "result": {
            "wait": {
              "remaining": 0,
              "trigger": null
            }
          }
        }
      ],
      "action/0/choose/2/sequence/2": [
        {
          "path": "action/0/choose/2/sequence/2",
          "timestamp": "2023-09-27T12:52:48.800282+00:00",
          "changed_variables": {
            "wait": {
              "remaining": 0,
              "trigger": null
            }
          },
          "result": {
            "params": {
              "domain": "switch",
              "service": "turn_off",
              "service_data": {},
              "target": {
                "entity_id": [
                  "switch.tp_link_power_strip_8108_kasa_smart_plug_8108_0"
                ]
              }
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1694293975312",
      "alias": "Maintain skink climate",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.low_reptile_humidity"
          ],
          "to": "on",
          "id": "humidity"
        },
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.temperature"
          ],
          "to": "on",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 10
          },
          "id": "temperature_cold"
        },
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.temperature"
          ],
          "to": "off",
          "id": "temperature_normal"
        },
        {
          "platform": "state",
          "entity_id": [
            "sun.sun"
          ],
          "from": null,
          "to": null,
          "id": "sun"
        }
      ],
      "condition": [
        {
          "condition": "or",
          "conditions": [
            {
              "condition": "and",
              "conditions": [
                {
                  "condition": "trigger",
                  "id": [
                    "humidity"
                  ]
                },
                {
                  "condition": "state",
                  "entity_id": "binary_sensor.reptile_water_level_ok",
                  "state": "off"
                }
              ],
              "alias": "Humidity trigger and water level ok"
            },
            {
              "condition": "not",
              "conditions": [
                {
                  "condition": "trigger",
                  "id": [
                    "humidity"
                  ]
                }
              ],
              "alias": "Any other trigger id"
            }
          ]
        }
      ],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": [
                    "temperature_cold"
                  ]
                }
              ],
              "sequence": [
                {
                  "service": "switch.turn_on",
                  "alias": "Turn on the heat element",
                  "target": {
                    "entity_id": "switch.tp_link_power_strip_8108_kasa_smart_plug_8108_1"
                  },
                  "data": {}
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": [
                    "temperature_normal"
                  ]
                }
              ],
              "sequence": [
                {
                  "service": "switch.turn_off",
                  "target": {
                    "entity_id": "switch.tp_link_power_strip_8108_kasa_smart_plug_8108_1"
                  },
                  "data": {}
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": [
                    "humidity"
                  ],
                  "enabled": false
                }
              ],
              "sequence": [
                {
                  "service": "switch.turn_on",
                  "alias": "Turn on the misting system",
                  "target": {
                    "entity_id": "switch.tp_link_power_strip_8108_kasa_smart_plug_8108_0"
                  },
                  "data": {}
                },
                {
                  "wait_for_trigger": [
                    {
                      "platform": "state",
                      "alias": "Humidity in tank is back to normal",
                      "entity_id": [
                        "binary_sensor.low_reptile_humidity"
                      ],
                      "to": "off"
                    },
                    {
                      "platform": "state",
                      "alias": "Water level becomes low",
                      "entity_id": [
                        "binary_sensor.reptile_water_level_ok"
                      ],
                      "to": null,
                      "from": "off"
                    }
                  ],
                  "timeout": {
                    "hours": 0,
                    "minutes": 2,
                    "seconds": 0,
                    "milliseconds": 0
                  },
                  "alias": "Check if mist should be turned off"
                },
                {
                  "service": "switch.turn_off",
                  "alias": "Turn off the misting system",
                  "target": {
                    "entity_id": "switch.tp_link_power_strip_8108_kasa_smart_plug_8108_0"
                  },
                  "data": {}
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": [
                    "sun"
                  ]
                }
              ],
              "sequence": [
                {
                  "if": [
                    {
                      "condition": "state",
                      "entity_id": "sun.sun",
                      "state": "below_horizon"
                    }
                  ],
                  "then": [
                    {
                      "service": "switch.turn_off",
                      "data": {},
                      "target": {
                        "entity_id": [
                          "switch.skink_plug_3",
                          "switch.kasa_smart_wi_fi_plug_2"
                        ]
                      }
                    }
                  ],
                  "else": [
                    {
                      "service": "switch.turn_on",
                      "data": {},
                      "target": {
                        "entity_id": [
                          "switch.skink_plug_3",
                          "switch.kasa_smart_wi_fi_plug_2"
                        ]
                      }
                    }
                  ]
                }
              ]
            }
          ],
          "default": [
            {
              "service": "notify.persistent_notification",
              "data": {
                "message": "Unhandled condition for skink climate.",
                "title": "Warning"
              }
            }
          ]
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HBBB29TBB2CK6BM3RBTKT8XV",
      "parent_id": "01HBBB29TB579JDQNAHM2WYFBB",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Maintain skink climate",
      "message": "triggered by state of sun.sun",
      "source": "state of sun.sun",
      "entity_id": "automation.maintain_reptile_humidity",
      "context_id": "01HBBB29TBB2CK6BM3RBTKT8XV",
      "when": 1695819048.779727,
      "domain": "automation"
    },
    {
      "when": 1695819048.881456,
      "state": "on",
      "entity_id": "switch.tp_link_power_strip_8108_kasa_smart_plug_8108_0",
      "icon": "mdi:water-pump",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Maintain skink climate",
      "context_message": "triggered by state of sun.sun",
      "context_source": "state of sun.sun",
      "context_entity_id": "automation.maintain_reptile_humidity"
    },
    {
      "when": 1695819168.878869,
      "state": "off",
      "entity_id": "switch.tp_link_power_strip_8108_kasa_smart_plug_8108_0",
      "icon": "mdi:water-pump",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Maintain skink climate",
      "context_message": "triggered by state of sun.sun",
      "context_source": "state of sun.sun",
      "context_entity_id": "automation.maintain_reptile_humidity"
    }
  ]
}

I should mention the original automation which the other were consolidated into was called “maintain_skink_humidity”, thus the context_entity_ids saying as such.

Hello kohbo, welcome to the forums!

Please post your automation.

Thank you! Here’s the full automation:

alias: Maintain skink climate
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.low_reptile_humidity
    to: "on"
    id: humidity
  - platform: state
    entity_id:
      - binary_sensor.temperature
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 10
    id: temperature_cold
  - platform: state
    entity_id:
      - binary_sensor.temperature
    to: "off"
    id: temperature_normal
  - platform: state
    entity_id:
      - sun.sun
    from: null
    to: null
    id: sun
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id:
              - humidity
          - condition: state
            entity_id: binary_sensor.reptile_water_level_ok
            state: "off"
        alias: Humidity trigger and water level ok
      - condition: not
        conditions:
          - condition: trigger
            id:
              - humidity
        alias: Any other trigger id
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - temperature_cold
        sequence:
          - service: switch.turn_on
            alias: Turn on the heat element
            target:
              entity_id: switch.tp_link_power_strip_8108_kasa_smart_plug_8108_1
            data: {}
      - conditions:
          - condition: trigger
            id:
              - temperature_normal
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.tp_link_power_strip_8108_kasa_smart_plug_8108_1
            data: {}
      - conditions:
          - condition: trigger
            id:
              - humidity
            enabled: false
        sequence:
          - service: switch.turn_on
            alias: Turn on the misting system
            target:
              entity_id: switch.tp_link_power_strip_8108_kasa_smart_plug_8108_0
            data: {}
          - wait_for_trigger:
              - platform: state
                alias: Humidity in tank is back to normal
                entity_id:
                  - binary_sensor.low_reptile_humidity
                to: "off"
              - platform: state
                alias: Water level becomes low
                entity_id:
                  - binary_sensor.reptile_water_level_ok
                to: null
                from: "off"
            timeout:
              hours: 0
              minutes: 2
              seconds: 0
              milliseconds: 0
            alias: Check if mist should be turned off
          - service: switch.turn_off
            alias: Turn off the misting system
            target:
              entity_id: switch.tp_link_power_strip_8108_kasa_smart_plug_8108_0
            data: {}
      - conditions:
          - condition: trigger
            id:
              - sun
        sequence:
          - if:
              - condition: state
                entity_id: sun.sun
                state: below_horizon
            then:
              - service: switch.turn_off
                data: {}
                target:
                  entity_id:
                    - switch.skink_plug_3
                    - switch.kasa_smart_wi_fi_plug_2
            else:
              - service: switch.turn_on
                data: {}
                target:
                  entity_id:
                    - switch.skink_plug_3
                    - switch.kasa_smart_wi_fi_plug_2
    default:
      - service: notify.persistent_notification
        data:
          message: Unhandled condition for skink climate.
          title: Warning
mode: single

you disabled the condition, it doesn’t disable the sequence.

1 Like

That makes a lot of sense, in hindsight. Thank you I assume there’s no simple way to disable an entire choice except commenting it all out then?

I don’t believe there is a way to quickly disable them all.

No worries. Thanks, again!