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

Electricity price in cents instead of euros #20

Open
oskari opened this issue Sep 12, 2023 · 16 comments
Open

Electricity price in cents instead of euros #20

oskari opened this issue Sep 12, 2023 · 16 comments
Labels
enhancement New feature or request

Comments

@oskari
Copy link

oskari commented Sep 12, 2023

The one big problem I have with SHF using euros instead of cents is that:
a) 15 Cents per kwh is easier to communicate than 0.15 euros per kwh
b) HA automation fields don't support decimals. Let's say I want to check if the price is below 15 cents to charge my car. Have to make it a custom sensor or use templates. Rather just use the visual automation maker
image

Maybe an option on which unit to use? Or just use cents always?

@oskari oskari changed the title [0.2.X] Electricity price in cents instead of euros Electricity price in cents instead of euros Sep 12, 2023
@T3m3z
Copy link
Owner

T3m3z commented Sep 13, 2023

Hello and thank you for this enhancement proposal!

I see your point. People usually talk about c/kWh when talking about electricity prices. Selecting €/kWh just happened as the API producing this data uses that unit and it just stuck. Anyway, I'm a bit hesitant to change this as quite many people already have this installed and so far there hasn't been much talk about this being an issue.

For the B part: it is possible to use decimal numbers too. Your locale most probably just expects comma as a decimal separator. Tested this a few minutes ago with my HomeAssistant version 2023.9.1 and I was able to use this as the trigger and successfully run actions:
image

@T3m3z T3m3z added the enhancement New feature or request label Sep 13, 2023
@T3m3z
Copy link
Owner

T3m3z commented Sep 13, 2023

Making the unit selectable might not be possible or might create more confusion than it helps. For example I think that changing unit of "SHF Max Price allowed" slider is not possible dynamically. Or if it is, then please tell me!

@Jupsu3
Copy link

Jupsu3 commented Oct 15, 2023

I would also like to have prices in cents, would it be possible to make second branch or something for that?

@Routout
Copy link

Routout commented Oct 15, 2023

I would also like to have prices in cents, would it be possible to make second branch or something for that?

There is a fork which seem to be in cents. I haven't tested it, but maybe it's useful for you?
https://github.com/techmantel/spotprices2ha

@T3m3z
Copy link
Owner

T3m3z commented Nov 1, 2023

Maybe voting would be best way to settle this.

So please react to this comment with following emoji:

  • prices in cents is better: thumbs up
  • prices in euros is better: heart emoji
  • does not matter to you: haha/laughing emoji

Emojis were selected due to their availability on one of the internet forum where quite many of the Finnish users are.

@dillonfi
Copy link

dillonfi commented Nov 1, 2023

I vote for euros. Reasons:

  • HA already uses euros internally e.g. in utility meter
  • It's not conventional to use some other monetary unit than the actual currency itself. Of course in some cases monetary transactions are calculated using a 100 as multiplier to avoid floating point arithmetic. But in this case floats cannot be avoided anyhow because the precision of the prices is less than 1 cent.

@T3m3z
Copy link
Owner

T3m3z commented Nov 1, 2023

And a disclaimer: c/kWh should have majority of votes in order for the change to happen. Because if 50% vote yes and 50% vote no, then 50% of people will have to make dramatic changes to their current implementation and the number of unhappy people would stay roughly the same.

Also new pros/cons (like dillonfi's) are highly appreciated and will affect the final decision.

@oskari
Copy link
Author

oskari commented Nov 1, 2023

For the B part: it is possible to use decimal numbers too. Your locale most probably just expects comma as a decimal separator.
I think it's something else than locale. I can inspect the input and see that the step is "0.1" (Firefox)
image
My locale settings are:
image

And I'm voting for c/kWh because:

  • At least in Finland everybody talks about the electricity price in cents per kwh and it's confusing and mentally taxing to convert them between euros and cents
  • As my original issue explains, with my settings I cannot use the €/kwh values directly in automations

@T3m3z
Copy link
Owner

T3m3z commented Nov 1, 2023

  • As my original issue explains, with my settings I cannot use the €/kwh values directly in automations

Oh, I didn't check whether browsers affect this or not and I made too quick conclusions before investigating. It seems that Firefox for some reason is very strict about this "step". Or stricter than Chrome.

Anyway, after realizing this, I have two workarounds for you:

  1. Start as previously but before saving the automation select three dots on top right corner and select "Edit in YAML". Then press Save. After this initial save you can continue editing with visual editor (use three dots to get back there).
  2. If you want to use visual editor all the time, then using value_template of Numeric State trigger can be used to alter the value before comparison to above/below is made. So you could multiply €/kWh with 100 to get c/kWh and then use c/kWh in Numeric State triggers. Value template "{{ state.state | float * 100}}" without quotation marks should do the trick.
    image
{{ state.state | float * 100}}

I would like to know whether either of these workarounds ease your pain with this.

What comes to the original problem: I would recommend creating an issue on Home Assistant repo or asking about this issue on https://community.home-assistant.io/ about this. For me it doesn't make sense to restrict numeric state trigger to be only usable with one decimal as the sensors might give outputs with arbitrary number of decimals. Does this make sense?

@T3m3z
Copy link
Owner

T3m3z commented Nov 1, 2023

Third possible workaround: use Input Number helpers where you could set €/kWh values like 0,1234 and then use Numeric state triggers configured to trigger based on another entity (this setting is called "Numeric value of another entity").

@T3m3z
Copy link
Owner

T3m3z commented Nov 10, 2023

I did some research and learned something new. It is possible to use anchors and aliases in YAML to reuse certain set values which makes it easy to change "€/kWh" to "c/kWh" for example in the YAML file even though Home Assistant doesn't allow templating unit_of_measurement fields.

So please check https://github.com/T3m3z/spotprices2ha/tree/currency_unit and change rows 9-11 of spot-price.yaml according to your needs. This change needs testing before I can merge this into main branch. So it would be nice if you could do some testing and report findings here.

@oskari
Copy link
Author

oskari commented Nov 17, 2023

I'm getting an error when checking the config:
Package spot_price setup failed. Component shf_config Integration 'shf_config' not found.

This is probably related that I have in my configuration.yaml:

homeassistant:
  packages: !include_dir_named packages

So I have packages -folder where I have a file called spot_price.yaml (Had to change the dash to underscore for include_dir_named to work back when I reworked this structure)

Any idea if I can get this to work with such syntax? Should I move the shf_config to configuration.yaml?

@T3m3z
Copy link
Owner

T3m3z commented Nov 18, 2023

The error you see is actually caused by my code. Somehow (maybe through Home ASsistant CLI) I was able to make those changes and restart HomeAssistant. That just caused some errors on the log.

The problem is that HomeAssistant tries to interpret that "shf_config" part on spot-price.yaml as an integration (which it is not). I have an idea how to fix this. I will make an update to the repo soon (need to do some houshold chores etc. normal life first :) ).

@T3m3z
Copy link
Owner

T3m3z commented Nov 19, 2023

I have now made an attempt to fix this @oskari . So please check https://github.com/T3m3z/spotprices2ha/blob/currency_unit/spot-price.yaml

My previous attempt was flawed. Now it should work. Just follow the instructions starting from row 8 (basically just altering price_factor on row 41, energy_price_unit on row 70 and currency_unit on row 200.

Please note that changing units on the fly will cause some logged errors/warnings related to statistics integration. I haven't yet investigated how much they cause harm (if any).

@oskari
Copy link
Author

oskari commented Nov 23, 2023

I think we need to use price_factor on https://github.com/T3m3z/spotprices2ha/blob/currency_unit/spot-price.yaml#L53 ? Because if I change currency_unit to cents it affects the price1/2 fields too?

image
image

edit: My price1 is wrong, but I think the issue is valid.

@T3m3z
Copy link
Owner

T3m3z commented Nov 30, 2023

Sorry for the delay. Everyday life has been my priority one lately.

Your point was valid. Price1 and Price2 got multiplied mistakenly with price_factor even though they were already cents. I have corrected this now: https://github.com/T3m3z/spotprices2ha/blob/currency_unit/spot-price.yaml#L53

Sorry for the bug and thank you for reporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants