BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
624 stars 62 forks source link

Wheel of fortune spin support #431

Closed BottlecapDave closed 1 year ago

BottlecapDave commented 1 year ago

Describe the feature

A sensor for electricity and gas to determine how many wheel of fortune spins are remaining

A service to support executing a wheel of fortune spin. Should return the amount won.

Expected behavior

With these sensors, it should then be possible to configure automations to automatically execute the wheel of fortune spins and do something off the back if money is won

andyblac commented 1 year ago

has anyone ever won anything ?

BottlecapDave commented 1 year ago

I think I won a £1 once :p

owenashurst commented 1 year ago

There's no API for the wheel of fortune.

BottlecapDave commented 1 year ago

There is, it's just not available under the REST API. The feature will be available in the next release.

owenashurst commented 1 year ago

There is, it's just not available under the REST API. The feature will be available in the next release.

Oh really? Have you got a link to it? I don't see it on their docs here: https://developer.octopus.energy/docs/api/

BottlecapDave commented 1 year ago

It uses their graphql API, which is self documenting. The queries can be found at https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/blob/develop/custom_components/octopus_energy/api_client/__init__.py#L265

BottlecapDave commented 1 year ago

This is now available in v9.0.0 release.

aaron-trout commented 1 year ago

Thanks for implementing this @BottlecapDave

I tried to use the automation provided in services.md but I cant get it to work. The problem seems to be with the {{ trigger.entity_id }} in the action; I can't see any docs on trigger in the templating; it seems to not exist unless I am missing something 🤔

Screenshot 2023-11-25 at 11 05 18

Any thoughts / would you be able to update the doc there with some more info?

Thanks!

BottlecapDave commented 1 year ago

Trigger variables are available via all automations. I'm not sure if the UI is interpreting something odd in the automation. The only thing I can suggest (and I'll update the docs) is to have two separate automations

- alias: OE - Spin Gas Wheel Of Fortune
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sensor.octopus_energy_xxx_wheel_of_fortune_spins_gas
      above: 0
  condition: []
  action:
    - repeat:
        count: >
          {{ states('sensor.octopus_energy_xxx_wheel_of_fortune_spins_gas') | int }}
        sequence:
          - service: octopus_energy.spin_wheel_of_fortune
            data: {}
            target:
              entity_id: >
                {{ 'sensor.octopus_energy_xxx_wheel_of_fortune_spins_gas' }}
- alias: OE - Spin Electricity Wheel Of Fortune
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sensor.octopus_energy_xxx_wheel_of_fortune_spins_electricity
      above: 0
  condition: []
  action:
    - repeat:
        count: >
          {{ states('sensor.octopus_energy_xxx_wheel_of_fortune_spins_electricity') | int }}
        sequence:
          - service: octopus_energy.spin_wheel_of_fortune
            data: {}
            target:
              entity_id: >
                {{ 'sensor.octopus_energy_xxx_wheel_of_fortune_spins_electricity' }}
andyblac commented 1 year ago

Thanks for implementing this @BottlecapDave

I tried to use the automation provided in services.md but I cant get it to work. The problem seems to be with the {{ trigger.entity_id }} in the action; I can't see any docs on trigger in the templating; it seems to not exist unless I am missing something 🤔

Screenshot 2023-11-25 at 11 05 18

Any thoughts / would you be able to update the doc there with some more info?

Thanks!

try this

repeat:
  count: '{{ states(trigger.entity_id) | int }}'
  sequence:
    - service: octopus_energy.spin_wheel_of_fortune
      data: {}
      target:
        entity_id: '{{ trigger.entity_id }}'

I have fond that auttomation do not like | > etc

BottlecapDave commented 1 year ago

@aaron-trout Let me know which one of the above works for you (trigger would be preferable) and I'll update the docs. I can't test at the moment unfortunately as I have no spins left for this month

andyblac commented 1 year ago

@aaron-trout Let me know which one of the above works for you (trigger would be preferable) and I'll update the docs. I can't test at the moment unfortunately as I have no spins left for this month

in that case try, this is probably the better way of doing it.

- alias: OE - Spin Wheel Of Fortune
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sensor.octopus_energy_xxx_wheel_of_fortune_spins_electricity
      above: 0
    - platform: numeric_state
      entity_id: sensor.octopus_energy_xxx_wheel_of_fortune_spins_gas
      above: 0
  condition: []
  action:
    - repeat:
        count: '{{ states(trigger.entity_id) | int }}'
        sequence:
          - service: octopus_energy.spin_wheel_of_fortune
            data: {}
            target:
              entity_id: '{{ trigger.entity_id }}'

and remember, you can't test it by manually running it, as that has NO trigger. and thus no entity_id, you will have to wait for the sensor to get a free spin.

aaron-trout commented 1 year ago

you can't test it by manually running it, as that has NO trigger. and thus no entity_id

💡! That makes sense, and I think indeed I have also used up my spins this month already. I'll set up the automation and then check on it after it automatically runs later.

Thanks!

danieltwagner commented 1 year ago

I installed the spinner automation after I already had spins for the current month. As numeric_state will only trigger on state change and not when the automation is added I then ran it manually, and also saw this issue, just as @andyblac already pointed out.

I then manually adjusted the value down to 0 and back up to 2 for my electricity spins from developer tools and can confirm that the automation works fine as it is currently documented in services.md. Perhaps it's worth adding a note about the behaviour of numeric_state in case you strongly prefer the trigger. Having two automations adds more clutter but does make them manually executable, which might be preferable.