InventoCasa/ha-advanced-blueprints

Script doesn't work

Alexandros89 opened this issue · 9 comments

Hi, this is my configuration:

alias: ACS Auto 2.0
description: ""
use_blueprint:
path: PV_Excess_Control/pv_excess_control.yaml
input:
automation_id: Acs 2.0
pv_power: sensor.exptot
load_power: sensor.imptot
appliance_switch: switch.sonoff_10015f8b46_2
appliance_switch_interval: 1
actual_power: sensor.sonoff_10015f8b46_power_2
dynamic_current_appliance: false
export_power: sensor.energia_eccesso

and this is my step details
Executed: 19 ottobre 2023 alle ore 09:54:24
Result:
params:
domain: pyscript
service: pv_excess_control
service_data:
automation_id: Acs 2.0
appliance_priority: 1
export_power: sensor.energia_eccesso
pv_power: sensor.exptot
load_power: sensor.imptot
home_battery_level: null
min_home_battery_level: 100
dynamic_current_appliance: false
appliance_phases: 1
min_current: 6
max_current: 16
appliance_switch: switch.sonoff_10015f8b46_2
appliance_switch_interval: 1
appliance_current_set_entity: null
actual_power: sensor.sonoff_10015f8b46_power_2
defined_current: 6
appliance_on_only: false
grid_voltage: 230
import_export_power: null
home_battery_capacity: 0
solar_production_forecast: null
appliance_once_only: false
target: {}
running_script: false

i don't find the problem, i have a lot of excess but the script doesn't start

Same here....

Executed: 25. Oktober 2023 um 10:18:46
Result:
params:
domain: pyscript
service: pv_excess_control
service_data:
automation_id: PVExcesstoPowerBadEG
appliance_priority: 1
export_power: sensor.power_meter_active_power
pv_power: sensor.inverter_input_power
load_power: sensor.inverter_active_power
home_battery_level: sensor.battery_state_of_capacity
min_home_battery_level: 10
dynamic_current_appliance: false
appliance_phases: 1
min_current: 6
max_current: 16
appliance_switch: switch.bad_eg_2_2
appliance_switch_interval: 5
appliance_current_set_entity: null
actual_power: sensor.bad_eg_electric_consumption_w_2_2
defined_current: 0.8
appliance_on_only: false
grid_voltage: 230
import_export_power: null
home_battery_capacity: 5
solar_production_forecast: sensor.energy_production_today_remaining
appliance_once_only: false
target: {}
running_script: false

I have the suspicion that both of you provide (partially) wrong sensor values for import, export or PV power.
Please paste an excerpt of your Home Assistant Logs, which contain the debug logs from the script.

Having the same issue, I don't see anything in the main log that would indicate that the script is running at all. How does one test to make sure the script is running?

Having the same issue, I don't see anything in the main log that would indicate that the script is running at all. How does one test to make sure the script is running?

If you've enabled the debug logs as described in the instructions, you can post an excerpt from your home assistant logfile here.

I am seeing a couple of issues related to this. The symptoms:
#1 The information given in the readme to turn on debug information seems incorrect. Does not work with this syntax.
#2 The logs show the registered device log information.
#3 When disabling an automation and enabling it again, the script does not reliably come to live again. Also when repeatedly triggering the automation. Again the log shows the device registration output. But there are no repeated calls to the script.

I can revive it when editing the py file with the file editor. This seems to unload it from HA and then re-triggering the automation. Then the excess control works. IMHO there is somehow an issue with getting the self triggering instanciated.

After some heavy debugging, I know what is going on and why the code is disfunctional for so many users. In the end it is quite obvious. The code needs an overhaul as some concepts are not working with the current HA releases.
@InventoCasa Do you want pull requests, or should I fork the code and move things somewhere else?

The key problem and more:
As suspected the self triggering in combination with the trigger variable to ensure only one running instance does not work at all. The current HA releases kill any running time trigger, if you start an automation. Now on the first call, the trigger variable gets set from None to the function pointer. And this value remains forever. Due to that reason, the script never gets re-launched, once an automation has been triggered for the second time.
So I changed the code to launch the self.trigger_factory() at any init. In the on_time function I then check whether priority is the highest and only execute then. This still has the flaw that the user must not use the same priority twice (which one should not). But with that restriction the automation works well. Just one instance running robustly.
Now there is more on the code that could be optimized. Just to mention a few: Propper rounding off current values, avoiding overshoots due to dynamic appliances which do not instantly follow the current set, on/off sequences etc.

As said I am happy to submit change requests, if this is still maintained. Otherwise I would fork. Just let me know.

@stefan73 PRs would be nice. I'm always glad about other collaborators regarding fixes and improvements on this script, as my time is quite limited at the moment.

EDIT: Soooo.... the android clipboard screwed me over. I only had ~375 lines of code where there should be 500 in the files. This is so dumb, sorry. Maybe the people with the same error in the homeassistant forums have used their mobile phones and didn't properly check, either.

So, I tried @stefan73 fork, but executing the automation just returns the following error:
The log spits out the following Message:

2024-04-02
19:40:56.934
ERROR
(MainThread)
[homeassistant.components.automation.g arage_solarladung] Garage_Solarladung:Error executing script. Service not found for call_service
at pos
1: Service
pyscript.pv_excess_control not found.

The script is in the correct folder /pyscript (I hope - it's under the same folder as my configuration.yaml). I have no idea why it wouldn't activate. I tried restarting several times. I checked for spelling about 20 times. The file is named "pv_excess_control.py".

Please help.

There is an SPACE within homeassistant.components.automation.g arage_solarladung

And I had to use the same name for alias and automation_id, but automation_id needs lowercase letters and all spaces are replaced by underscores _


alias: ACS Auto 2_0
description: ""
use_blueprint:
path: PV_Excess_Control/pv_excess_control.yaml
input:
automation_id: acs_auto_2_0