-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Comments
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
which is showing you using an input_text not an input_number. In this scenario, you don't need the |
Hello,
Thanks, it could be a rookie error.
Anyway, I tried that since, when I used variables in the automation, I
could never get it to work, It printed errors about wanting a text and
getting a number (and I think vice-versa).. Piping through string never
made any difference.
I am actually looking to calculate the value, so initially I referenced an
automation variable defined like target_hours:
"{{states(max_required_hours) | string }}"
Could there be anything I could be missing and so not defining the helper(s) as
expected?
Anyway, I then tried different things: I initialised the variable in
different ways like:
1- max_required_hours: "2"
Executed: 19 February 2025 at 13:57:37
Error: Target hours must be in half hour increments (e.g. 0.5 = 30 minutes;
1 = 60 minutes).
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: unknown
entity_id:
- binary_sensor.octopus_energy_target_battery
target:
entity_id:
- binary_sensor.octopus_energy_target_battery
running_script: false
2- then defined it as max_required_hours: "{{2.0}}"
Executed: 19 February 2025 at 14:00:17
Error: Error rendering data template: AttributeError: 'float' object has no
attribute 'lower'
3- then defined it as max_required_hours: 2
Executed: 19 February 2025 at 13:55:10
Error: Error rendering data template: AttributeError: 'int' object has no
attribute 'lower'
4- then max_required_hours: "2.0" with target_hours:
"{{states(''input_text.max_hours_battery') | string }}"
Executed: 19 February 2025 at 14:19:22
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
5- then max_required_hours: "2.0" with target_hours:
"{{max_required_hours}}"
Executed: 19 February 2025 at 14:16:11
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
entity_id:
- binary_sensor.octopus_energy_target_battery
target:
entity_id:
- binary_sensor.octopus_energy_target_battery
running_script: false
Eventually I tried the input text, but could never run it.
6- When defined as max_required_hours:
"{{states('input_text.max_hours_battery') |default('2.0') }}"
Executed: 19 February 2025 at 13:51:53
Error: Error rendering data template: AttributeError: 'float' object has no
attribute 'lower'
All I am trying is to use a variable that I will eventually replace with a
formula to be able to have a calculated value.
Your help is appreciated, I assume having a calculated value is a
normal use case and that unless I am having an input value I would not need a input_number?
…On Tue, 18 Feb 2025 at 13:58, David Kendall ***@***.***> wrote:
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.png (view on web)
<https://github.com/user-attachments/assets/2c0bea26-1266-4fe4-ba8e-7f17591eafc0>
—
Reply to this email directly, view it on GitHub
<#1227 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQWZFN7NU3HYGZDTPZIFBZD2QM4AVAVCNFSM6AAAAABXLULZTOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRVG44TOOBXGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
[image: BottlecapDave]*BottlecapDave* left a comment
(BottlecapDave/HomeAssistant-OctopusEnergy#1227)
<#1227 (comment)>
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.png (view on web)
<https://github.com/user-attachments/assets/2c0bea26-1266-4fe4-ba8e-7f17591eafc0>
—
Reply to this email directly, view it on GitHub
<#1227 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQWZFN7NU3HYGZDTPZIFBZD2QM4AVAVCNFSM6AAAAABXLULZTOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRVG44TOOBXGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Just another attempt, now I am really struggling... action: action: octopus_energy.update_target_config trace: Executed: 20 February 2025 at 21:25:08 |
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 ( |
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. |
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. |
I used to edit on automation UI, usually with that yaml named option.
But most recently I edited in text directly for this gest, using some add
on.. it is much more time consuming but it proved this is not the issue
As you are making assumptions in the code and trimming quotes etc, even
someone editing with vi with ssh will not get it to work...
I could do a test, even if this is no longer very urgent for me as I am no
longer on the agile rate.
…On Tue, 25 Feb 2025, 06:34 David Kendall, ***@***.***> wrote:
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.
—
Reply to this email directly, view it on GitHub
<#1227 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQWZFN7H7HDTSNPBEC27Z732RQFHDAVCNFSM6AAAAABXLULZTOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBQG44TGMZUGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
[image: BottlecapDave]*BottlecapDave* left a comment
(BottlecapDave/HomeAssistant-OctopusEnergy#1227)
<#1227 (comment)>
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.
—
Reply to this email directly, view it on GitHub
<#1227 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQWZFN7H7HDTSNPBEC27Z732RQFHDAVCNFSM6AAAAABXLULZTOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBQG44TGMZUGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
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:
entity_id:
conditions: []
actions:
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:
entity_id:
conditions: []
actions:
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
The text was updated successfully, but these errors were encountered: