Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for service to set target parameters needs update #1227

Open
2 tasks
PauloGoncalves86 opened this issue Feb 18, 2025 · 7 comments
Open
2 tasks

Example for service to set target parameters needs update #1227

PauloGoncalves86 opened this issue Feb 18, 2025 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@PauloGoncalves86
Copy link

PauloGoncalves86 commented Feb 18, 2025

Describe the bug

The example provided for setting the target sensor via services on page https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/services/ does not work in the current version of home assistant. Specifically the target_hours:
mode: single
alias: Update target rate config
triggers:

  • trigger: state
    entity_id:
    • input_number.octopus_energy_target_hours
    • input_text.octopus_energy_target_from
    • input_text.octopus_energy_target_to
    • input_text.octopus_energy_target_offset
      conditions: []
      actions:
  • action: octopus_energy.update_target_config
    data:
    target_hours: >
    "{{ states('input_number.octopus_energy_target_hours') | string }}"
    target_start_time: >
    {{ states('input_text.octopus_energy_target_from') }}
    target_end_time: >
    {{ states('input_text.octopus_energy_target_to') }}
    target_offset: >
    {{ states('input_text.octopus_energy_target_offset') }}
    target:
    entity_id: binary_sensor.octopus_energy_target_example

Reproduction steps

Setup automation based on example:
mode: single
alias: Update target rate config
triggers:

  • trigger: state
    entity_id:
    • input_number.octopus_energy_target_hours
    • input_text.octopus_energy_target_from
    • input_text.octopus_energy_target_to
    • input_text.octopus_energy_target_offset
      conditions: []
      actions:
  • action: octopus_energy.update_target_config
    data:
    target_hours: >
    "{{ states('input_number.octopus_energy_target_hours') | string }}"
    target_start_time: >
    {{ states('input_text.octopus_energy_target_from') }}
    target_end_time: >
    {{ states('input_text.octopus_energy_target_to') }}
    target_offset: >
    {{ states('input_text.octopus_energy_target_offset') }}
    target:
    entity_id: binary_sensor.octopus_energy_target_example

When executing this variation:
action: octopus_energy.update_target_config
metadata: {}
data:
target_start_time: "{{ possible_period_start }}"
target_end_time: "{{ possible_period_end }}"
target_offset: "{{ initial_offset }}"
target_hours: "{{states('input_text.max_hours_battery') |string }}"
target:
entity_id: "{{ target_sensor }}"

...the "{{ states('input_number.octopus_energy_target_hours') | string }}" evaluates to a number and the function expects text.

The only way I could use it is by having a text string directly on the parameter, which is not what is needed, as the goal is to be able to have an automation calculating and setting the parameter of the target sensor dynamically.

Expected behaviour

One would expect it to trigger recalculation of the sensor but the execution reports errors and the service call is not made.
The text in the help page needs to be updated.

Tariff Code

E-1R-INTELLI-VAR-24-10-29-A

Integration Version

14.0.0

Home Assistant Version

2025.2.4

Fresh Install?

After upgrading

Home Assistant Logs

Versions:
Core
2025.2.4
Supervisor
2025.02.1
Operating System
14.2
Frontend
20250214.0

trace log:
Executed: 18 February 2025 at 13:14:27
Error: expected str for dictionary value @ data['target_hours']
Result:
params:
domain: octopus_energy
service: update_target_config
service_data:
target_start_time: '22:30'
target_end_time: '07:30'
target_offset: '-00:00:00'
target_hours: 1.5
entity_id:
- binary_sensor.octopus_energy_target_battery
target:
entity_id:
- binary_sensor.octopus_energy_target_battery
running_script: false

Confirmation

  • I confirm that I cannot find my solution within the documentation
  • I confirm that I cannot find my solution within the FAQ
@PauloGoncalves86 PauloGoncalves86 added the bug Something isn't working label Feb 18, 2025
@BottlecapDave
Copy link
Owner

Hello. I am using the same version of HA and I'm not having an issue with the example. The only thing I can see in what you posted is

target_hours: "{{states('input_text.max_hours_battery') |string }}"

which is showing you using an input_text not an input_number. In this scenario, you don't need the | string because the value is already a string.

Image

@PauloGoncalves86
Copy link
Author

PauloGoncalves86 commented Feb 19, 2025 via email

@PauloGoncalves86
Copy link
Author

Just another attempt, now I am really struggling...

action:

action: octopus_energy.update_target_config
metadata: {}
data:
target_start_time: '{{ possible_period_start }}'
target_end_time: '{{ possible_period_end }}'
target_offset: '{{ initial_offset }}'
target_hours: '{{states(''input_number.max_hours_battery'') | string }}'
target:
entity_id: '{{ target_sensor }}'

trace:

Executed: 20 February 2025 at 21:25:08
Error: expected str for dictionary value @ data['target_hours']
Result:
params:
domain: octopus_energy
service: update_target_config
service_data:
target_start_time: '22:30'
target_end_time: '07:30'
target_offset: '-00:00:00'
target_hours: 2.5
entity_id:
- binary_sensor.octopus_energy_target_battery
target:
entity_id:
- binary_sensor.octopus_energy_target_battery
running_script: false

@BottlecapDave
Copy link
Owner

I don't use the UI for setting up automations, so it might be something that the UI is doing when converting. It might be that you're using single quotes instead of double quotes for the target hours ('{{states(''input_number.max_hours_battery'') | string }}' instead of "{{states(''input_number.max_hours_battery'') | string }}")

@PauloGoncalves86
Copy link
Author

Good hint, I would not have thought that the UI and direct edit of files is leads to different results in HA.. Still, the UI is really useful to get results quickly.

You would not have implemented any code to do trimming of quotes or double quotes, would you, Dave?

Clearly a messy situation that I assume started before this integration...

In terms of docs, not easy to solve at all, unless anyone figures out a path that leads to a working example. Then it could be updated in the great overview you have of the services.

@BottlecapDave
Copy link
Owner

Am I correct in saying that when you post the example into your automation, you're using the "edit in yaml" mode to paste the code, or are you trying to do it in the UI? I believe the UI doesn't support templates. Unfortunately I can't easily try and recreate the situation in the UI because HA won't allow me to add any automations via the UI due to my setup.

@PauloGoncalves86
Copy link
Author

PauloGoncalves86 commented Feb 25, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants