InventoCasa / ha-advanced-blueprints

Advanced Blueprints combined with pyscript for extra useful automations
139 stars 33 forks source link

Script getting "None" for Appliance switch entity, fails #45

Closed darrendavid closed 6 months ago

darrendavid commented 7 months ago

I have my automation configured to turn on and off a dehumidifer using a Kasa smart plug. Here's the YAML for my automation:

data:
  automation_id: automation.pv_excess_power_dehumidifier
  appliance_priority: 2
  export_power: sensor.pv_export_power_to_grid_calculated
  pv_power: sensor.deye_sunsynk_sol_ark_pv_power_5
  load_power: sensor.deye_sunsynk_sol_ark_load_power_2
  home_battery_level: sensor.deye_sunsynk_sol_ark_battery_state_of_charge_2
  min_home_battery_level: 100
  dynamic_current_appliance: false
  appliance_phases: 1
  min_current: 6
  max_current: 16
  appliance_switch: switch.dehumidifier
  appliance_switch_interval: 5
  appliance_current_set_entity: null
  actual_power: sensor.dehumidifier_current_consumption
  defined_current: 6
  appliance_on_only: false
  grid_voltage: 240
  import_export_power: null
  home_battery_capacity: 8.8
  solar_production_forecast: null
  appliance_once_only: false

When the script runs, I get this error in the log:

2023-11-19 15:10:38.232 WARNING (MainThread) [custom_components.pyscript.file.pv_excess_control.on_time] [switch.dehumidifier (Prio 2)] Appliance state (=None) is neither ON nor OFF. Assuming OFF state.
2023-11-19 15:10:38.233 ERROR (MainThread) [custom_components.pyscript.file.pv_excess_control.on_time] Exception in <file.pv_excess_control.on_time> line 18:
        domain = entity_id.split('.')[0]
                 ^
AttributeError: 'NoneType' object has no attribute 'split'

However, when I check the entity with developer tools, it shows the value as "off":

image

Unsure if these are related or not, but it's crashing the script as the split is not in a try/catch clause.

InventoCasa commented 7 months ago

Hi,

something must have happened on your side, e.g. renaming the humidifier entity id after executing the automation, or executing the automation somehow without having an appliance switch entity defined. Please re-add the switch entity in the automation and execute it once. Then immediately watch the debug logs of the script. It should log, which information (switch entity, ....) it received. Please post the logs once you did this.

Another idea would be that the issue is with the implementation of the Kasa integration. You could check by testing with another switch entity, which is not from the Kasa integration.