Troubleshooting ceiling fan automation that doesn't seem to be firing all the times that it should. Basically want to use my in line Shelly PM1 to determine the speed of the ceiling fan and then report the accurate speed state to the Bond RF controller

Home Assistant 2023.8.4
Supervisor 2023.08.3
Operating System 10.5
Frontend 20230802.1 - latest

Okay, the main issue I’ve got with my Bond and my ceiling fan and HA is that state tracking is pretty inconsistent, which causes my remotes to not always work. My plan was pretty much to put a PM1 in line so that it would know the current watt draw, and then have an automation run to update the bond with the speed, based on some watt ranges I had worked out. This seems to MOSTLY work, but… sometimes it doesn’t and I have no idea why.

This morning for example, the fan was on full speed overnight, keeping me nice and cool. I hit the remote button to turn it off (service call for fan:toggle) but it does nothing. I open the Bond app and it thinks the fan is off, when it’s definitely not. I open my automation and it hasn’t fired since last night, presumably when I turned the fan on in the first place. I skip directly to the part of the automation that performs the action to update the state if the watt usage is in the range for ‘off’ (0 to 1.7w) and it works.

So something isn’t triggering, yeah?

Here’s the yaml, if someone can tell me if there’s an obvious reason this isn’t always working.

If someone has a better way to achieve this, I’d be very open to it. Thanks!

alias: Ceiling Fan - set tracked power state
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.shelly_main_bedroom_overhead_fan_switch_0_power
    for:
      hours: 0
      minutes: 0
      seconds: 2
    above: 1.6
    below: 3
    id: Power 1
  - platform: numeric_state
    entity_id: sensor.shelly_main_bedroom_overhead_fan_switch_0_power
    for:
      hours: 0
      minutes: 0
      seconds: 2
    above: 3
    below: 5.5
    id: Power 2
  - platform: numeric_state
    entity_id: sensor.shelly_main_bedroom_overhead_fan_switch_0_power
    for:
      hours: 0
      minutes: 0
      seconds: 2
    above: 5.5
    below: 10
    id: Power 3
  - platform: numeric_state
    entity_id: sensor.shelly_main_bedroom_overhead_fan_switch_0_power
    for:
      hours: 0
      minutes: 0
      seconds: 2
    above: 10
    below: 15
    id: Power 4
  - platform: numeric_state
    entity_id: sensor.shelly_main_bedroom_overhead_fan_switch_0_power
    for:
      hours: 0
      minutes: 0
      seconds: 2
    above: 15
    below: 25
    id: Power 5
  - platform: numeric_state
    entity_id: sensor.shelly_main_bedroom_overhead_fan_switch_0_power
    for:
      hours: 0
      minutes: 0
      seconds: 2
    above: 25
    below: 40
    id: Power 6
  - platform: numeric_state
    entity_id: sensor.shelly_main_bedroom_overhead_fan_switch_0_power
    for:
      hours: 0
      minutes: 0
      seconds: 2
    below: 1.6
    id: Power 0
condition: []
action:
  - if:
      - condition: trigger
        id:
          - Power 1
    then:
      - service: bond.set_fan_speed_tracked_state
        data:
          entity_id: fan.ceiling_fan_1
          speed: 16
  - if:
      - condition: trigger
        id:
          - Power 2
      - condition: trigger
        id:
          - Power 2
    then:
      - service: bond.set_fan_speed_tracked_state
        data:
          entity_id: fan.ceiling_fan_1
          speed: 33
  - if:
      - condition: trigger
        id:
          - Power 3
    then:
      - service: bond.set_fan_speed_tracked_state
        data:
          entity_id: fan.ceiling_fan_1
          speed: 50
  - if:
      - condition: trigger
        id:
          - Power 4
    then:
      - service: bond.set_fan_speed_tracked_state
        data:
          entity_id: fan.ceiling_fan_1
          speed: 66
  - if:
      - condition: trigger
        id:
          - Power 5
    then:
      - service: bond.set_fan_speed_tracked_state
        data:
          entity_id: fan.ceiling_fan_1
          speed: 83
  - if:
      - condition: trigger
        id:
          - Power 6
    then:
      - service: bond.set_fan_speed_tracked_state
        data:
          entity_id: fan.ceiling_fan_1
          speed: 100
  - if:
      - condition: trigger
        id:
          - Power 0
    then:
      - service: bond.set_fan_speed_tracked_state
        data:
          entity_id: fan.ceiling_fan_1
          speed: 0
mode: single

Hey there and welcome to the forum! :slight_smile:

Please take a look at this topic and edit your post. :slight_smile:

There are many reasons why, one of them being to properly format your code! :wink: It’s not because this forum would be very harsh or pedantic, but it is simply not possible to see errors in YAML, if it is not properly formatted. Indentation is very important in YAML and without formatting, we can’t see if something’s wrong there.

Thanks a lot! :slight_smile:

I tried to format it correctly… the instructions said to use backticks at the start and end of the code block, so I included them but it clearly didn’t work. Not sure exactly how I should have done it to fix that but I can tell you that it shouldn’t be a yaml specific error since I built the automation in the UI. I’ll see if I can fix the code block though.

edit: it is fixed and I added some HA version info. Thanks for the pointer to the new poster FAQ!

Thanks for formatting, it makes reading much easier. :+1:

First thing I see, this is double:

      - condition: trigger
        id:
          - Power 2
      - condition: trigger
        id:
          - Power 2

Have you checked the automation trace, to see where it goes wrong? Might be helpful.

I would speculate, that maybe you’re not crossing the treshhold in some cases, and so it doesn’t trigger. Eg. there’s a gap between “Power 1” and “Power 2”. To be below 3 (P1) and above 3 (P2) leaves the exact value of 3 out of scope. If the numeric_state reports exactly 3, your automation shouldn’t trigger.

When I checked the last one in the morning when I noticed the issue, the most recent one was from the night before and it looked like it was basically successful. At the very least, it was in an on state (5) at the time. So, based on this output, I would have expected the Bond controller to have it in an on state and not in the off state I found it in.

People love their Bond controllers for RF fans but man, the lack of two way communication is a real bummer.

platform: numeric_state
entity_id: sensor.shelly_main_bedroom_overhead_fan_switch_0_power
for:
  hours: 0
  minutes: 0
  seconds: 2
above: 15
below: 25
id: Power 5

But that is a totally different problem. Based on the code you posted, you’re not actually sending anything to the integration. :wink: What you’re doing here, is setting a state, while not transmitting anything. :slight_smile:

Post the automation trace and we’ll see, if this automation is running properly.

Is this the automation trace? I had to download it from the trace page, yeah?

{
  "trace": {
    "last_step": "action/6/if/condition/0",
    "run_id": "184eb300e6cda0b248aaf6cc4ec36bab",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-09-07T04:12:22.209882+00:00",
      "finish": "2023-09-07T04:12:22.471921+00:00"
    },
    "domain": "automation",
    "item_id": "1692319796704",
    "trigger": "numeric state of sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
    "trace": {
      "trigger/4": [
        {
          "path": "trigger/4",
          "timestamp": "2023-09-07T04:12:22.209983+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.automation_56_2",
              "state": "on",
              "attributes": {
                "id": "1692319796704",
                "last_triggered": "2023-09-07T04:12:14.209863+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Ceiling Fan - set tracked power state"
              },
              "last_changed": "2023-08-26T12:47:50.571387+00:00",
              "last_updated": "2023-09-07T04:12:14.475824+00:00",
              "context": {
                "id": "01H9PXECG12AQHMPHJ5PW6WQ7W",
                "parent_id": "01H9PXEAHGJMC5GR816F1F7SM9",
                "user_id": null
              }
            },
            "trigger": {
              "id": "Power 5",
              "idx": "4",
              "alias": null,
              "platform": "numeric_state",
              "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
              "below": 25,
              "above": 15,
              "from_state": {
                "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
                "state": "15.0",
                "attributes": {
                  "state_class": "measurement",
                  "unit_of_measurement": "W",
                  "device_class": "power",
                  "friendly_name": "Shelly Main Bedroom Overhead Fan switch_0 power"
                },
                "last_changed": "2023-09-07T04:12:19.225077+00:00",
                "last_updated": "2023-09-07T04:12:19.225077+00:00",
                "context": {
                  "id": "01H9PXEHCSTRCRYXTT37Z8YJSK",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
                "state": "18.1",
                "attributes": {
                  "state_class": "measurement",
                  "unit_of_measurement": "W",
                  "device_class": "power",
                  "friendly_name": "Shelly Main Bedroom Overhead Fan switch_0 power"
                },
                "last_changed": "2023-09-07T04:12:20.208167+00:00",
                "last_updated": "2023-09-07T04:12:20.208167+00:00",
                "context": {
                  "id": "01H9PXEJBG7CJKEQ4YCH0YNJWS",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": 2
              },
              "description": "numeric state of sensor.shelly_main_bedroom_overhead_fan_switch_0_power"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-09-07T04:12:22.210890+00:00",
          "changed_variables": {
            "context": {
              "id": "01H9PXEMA1X9GDK075VWZFNNGC",
              "parent_id": "01H9PXEJBG7CJKEQ4YCH0YNJWS",
              "user_id": null
            }
          }
        }
      ],
      "action/0/if": [
        {
          "path": "action/0/if",
          "timestamp": "2023-09-07T04:12:22.210943+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/if/condition/0": [
        {
          "path": "action/0/if/condition/0",
          "timestamp": "2023-09-07T04:12:22.210967+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2023-09-07T04:12:22.211023+00:00"
        }
      ],
      "action/1/if": [
        {
          "path": "action/1/if",
          "timestamp": "2023-09-07T04:12:22.211059+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/1/if/condition/0": [
        {
          "path": "action/1/if/condition/0",
          "timestamp": "2023-09-07T04:12:22.211079+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2023-09-07T04:12:22.211127+00:00"
        }
      ],
      "action/2/if": [
        {
          "path": "action/2/if",
          "timestamp": "2023-09-07T04:12:22.211173+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/2/if/condition/0": [
        {
          "path": "action/2/if/condition/0",
          "timestamp": "2023-09-07T04:12:22.211197+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2023-09-07T04:12:22.211245+00:00"
        }
      ],
      "action/3/if": [
        {
          "path": "action/3/if",
          "timestamp": "2023-09-07T04:12:22.211279+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/3/if/condition/0": [
        {
          "path": "action/3/if/condition/0",
          "timestamp": "2023-09-07T04:12:22.211298+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/4": [
        {
          "path": "action/4",
          "timestamp": "2023-09-07T04:12:22.211342+00:00",
          "result": {
            "choice": "then"
          }
        }
      ],
      "action/4/if": [
        {
          "path": "action/4/if",
          "timestamp": "2023-09-07T04:12:22.211375+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/4/if/condition/0": [
        {
          "path": "action/4/if/condition/0",
          "timestamp": "2023-09-07T04:12:22.211394+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/4/then/0": [
        {
          "path": "action/4/then/0",
          "timestamp": "2023-09-07T04:12:22.211615+00:00",
          "result": {
            "params": {
              "domain": "bond",
              "service": "set_fan_speed_tracked_state",
              "service_data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 83
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ],
      "action/5": [
        {
          "path": "action/5",
          "timestamp": "2023-09-07T04:12:22.471039+00:00"
        }
      ],
      "action/5/if": [
        {
          "path": "action/5/if",
          "timestamp": "2023-09-07T04:12:22.471099+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/5/if/condition/0": [
        {
          "path": "action/5/if/condition/0",
          "timestamp": "2023-09-07T04:12:22.471122+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/6": [
        {
          "path": "action/6",
          "timestamp": "2023-09-07T04:12:22.471192+00:00"
        }
      ],
      "action/6/if": [
        {
          "path": "action/6/if",
          "timestamp": "2023-09-07T04:12:22.471232+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/6/if/condition/0": [
        {
          "path": "action/6/if/condition/0",
          "timestamp": "2023-09-07T04:12:22.471255+00:00",
          "result": {
            "result": false
          }
        }
      ]
    },
    "config": {
      "id": "1692319796704",
      "alias": "Ceiling Fan - set tracked power state",
      "description": "",
      "trigger": [
        {
          "platform": "numeric_state",
          "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 2
          },
          "above": 1.6,
          "below": 3,
          "id": "Power 1"
        },
        {
          "platform": "numeric_state",
          "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 2
          },
          "above": 3,
          "below": 5.5,
          "id": "Power 2"
        },
        {
          "platform": "numeric_state",
          "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 2
          },
          "above": 5.5,
          "below": 10,
          "id": "Power 3"
        },
        {
          "platform": "numeric_state",
          "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 2
          },
          "above": 10,
          "below": 15,
          "id": "Power 4"
        },
        {
          "platform": "numeric_state",
          "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 2
          },
          "above": 15,
          "below": 25,
          "id": "Power 5"
        },
        {
          "platform": "numeric_state",
          "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 2
          },
          "above": 25,
          "below": 40,
          "id": "Power 6"
        },
        {
          "platform": "numeric_state",
          "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
          "for": {
            "hours": 0,
            "minutes": 0,
            "seconds": 2
          },
          "below": 1.6,
          "id": "Power 0"
        }
      ],
      "condition": [],
      "action": [
        {
          "if": [
            {
              "condition": "trigger",
              "id": [
                "Power 1"
              ]
            }
          ],
          "then": [
            {
              "service": "bond.set_fan_speed_tracked_state",
              "data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 16
              }
            }
          ]
        },
        {
          "if": [
            {
              "condition": "trigger",
              "id": [
                "Power 2"
              ]
            },
            {
              "condition": "trigger",
              "id": [
                "Power 2"
              ]
            }
          ],
          "then": [
            {
              "service": "bond.set_fan_speed_tracked_state",
              "data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 33
              }
            }
          ]
        },
        {
          "if": [
            {
              "condition": "trigger",
              "id": [
                "Power 3"
              ]
            }
          ],
          "then": [
            {
              "service": "bond.set_fan_speed_tracked_state",
              "data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 50
              }
            }
          ]
        },
        {
          "if": [
            {
              "condition": "trigger",
              "id": [
                "Power 4"
              ]
            }
          ],
          "then": [
            {
              "service": "bond.set_fan_speed_tracked_state",
              "data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 66
              }
            }
          ]
        },
        {
          "if": [
            {
              "condition": "trigger",
              "id": [
                "Power 5"
              ]
            }
          ],
          "then": [
            {
              "service": "bond.set_fan_speed_tracked_state",
              "data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 83
              }
            }
          ]
        },
        {
          "if": [
            {
              "condition": "trigger",
              "id": [
                "Power 6"
              ]
            }
          ],
          "then": [
            {
              "service": "bond.set_fan_speed_tracked_state",
              "data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 100
              }
            }
          ]
        },
        {
          "if": [
            {
              "condition": "trigger",
              "id": [
                "Power 0"
              ]
            }
          ],
          "then": [
            {
              "service": "bond.set_fan_speed_tracked_state",
              "data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 0
              }
            }
          ]
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01H9PXEMA1X9GDK075VWZFNNGC",
      "parent_id": "01H9PXEJBG7CJKEQ4YCH0YNJWS",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Ceiling Fan - set tracked power state",
      "message": "triggered by numeric state of sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
      "source": "numeric state of sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
      "entity_id": "automation.automation_56_2",
      "context_id": "01H9PXEMA1X9GDK075VWZFNNGC",
      "when": 1694059942.210035,
      "domain": "automation"
    }
  ]
}

Yep, that’s the trace :+1: But it doesn’t show any signs of “not working”. It does exactly what you asked it for. :open_mouth:

Your automation get’s triggered by “Power 5”, because the state changes from 15.0 to 18.1.

            "trigger": {
              "id": "Power 5", #<----- trigger id
              "idx": "4",
              "alias": null,
              "platform": "numeric_state",
              "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
              "below": 25,
              "above": 15,
              "from_state": { #<----- from 15.0
                "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
                "state": "15.0",
                "attributes": {
                  "state_class": "measurement",
                  "unit_of_measurement": "W",
                  "device_class": "power",
                  "friendly_name": "Shelly Main Bedroom Overhead Fan switch_0 power"
                },
                "last_changed": "2023-09-07T04:12:19.225077+00:00",
                "last_updated": "2023-09-07T04:12:19.225077+00:00",
                "context": {
                  "id": "01H9PXEHCSTRCRYXTT37Z8YJSK",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "sensor.shelly_main_bedroom_overhead_fan_switch_0_power",
                "state": "18.1", #<----- to state 18.1
                "attributes": {
                  "state_class": "measurement",
                  "unit_of_measurement": "W",
                  "device_class": "power",
                  "friendly_name": "Shelly Main Bedroom Overhead Fan switch_0 power"
                },
                "last_changed": "2023-09-07T04:12:20.208167+00:00",
                "last_updated": "2023-09-07T04:12:20.208167+00:00",
                "context": {
                  "id": "01H9PXEJBG7CJKEQ4YCH0YNJWS",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": 2
              },
              "description": "numeric state of sensor.shelly_main_bedroom_overhead_fan_switch_0_power"
            }

So the trigger is totally ok, let’s see what happens next. All the if conditions get checked and result in “false” (as expected) until the action4 (which is the “Power5” in your automation => counting here starts with 0 not 1) is reached. There the if condition results in “true” and the service bond.set_fan_speed_tracked_state gets executed.

"action/4/if/condition/0": [
        {
          "path": "action/4/if/condition/0",
          "timestamp": "2023-09-07T04:12:22.211394+00:00",
          "result": {
            "result": true #<----- if condition is true
          }
        }
      ],
      "action/4/then/0": [
        {
          "path": "action/4/then/0",
          "timestamp": "2023-09-07T04:12:22.211615+00:00",
          "result": {
            "params": {
              "domain": "bond",
              "service": "set_fan_speed_tracked_state", #<----- here the service gets called
              "service_data": {
                "entity_id": "fan.ceiling_fan_1",
                "speed": 83
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ],

All as it should be. :slight_smile:

So I guess what I need to look at, is the fan entity and see why it got changed to zero in between then and the morning when I pressed the toggle. Thanks for helping me focus my troubleshooting!

Oh ok, so this is solved for you? :open_mouth: I expected you to digg deeper and come back with additional questions. :rofl: If so, just add to this topic, so people know, where you’re coming from. :slight_smile:

In general, I’d start the troubleshooting on the automations page under Settings. Wait for the fan to be “out-of-sync”, and then go to the automation page and sort the automations by “last triggered”. This narrows the automations down a bit. And then go to the automation traces to look for errors or faults. Note: the automation traces are always available for the last five runs of an automation. Don’t only check the last run, see, if the runs before may have done something unexpected. You can switch between these runs in the trace screen, in the top centre there is a pull down menu, where you can select which run to check.

:slight_smile:

Yeah, I’m going to dig deeper but you’re exactly right, I’m basically going to wait for it to happen again and see if I can go from soup to nuts in working through the troubleshooting flow so I can absolutely establish where the disconnect is… and then I’ll come back. So yeah, not ‘fixed’ but you can close the ticket lol. Thanks again for the guidance!

1 Like