HA Update Entity help

Hey,
I’m fairly new to HA, and especially to Yaml.

I managed to get the UK Transport API working (I seem to be the only one using it I think :rofl:). But it does work well for me, giving me the train and bus times successfully and accurately.

But I need to update my script so that it only calls on the API to update the times when requested - not constantly when I don’t need it, as otherwise it could end up costing a lot.

I considered adding a button card to my bus/train dashboard to click when I want to get the latest times. But am not sure how to “programme” this in the yaml or UI.

The pic shows my yaml for the UK Transport, and it’s working perfectly. But I’m not sure how to add something in to stop it constantly updating, and get it to only update when I ask it to.

Any suggestions would be great! :pray:
As I say, I’m new to HA and yaml, so apologies if this is obvious, or if I have to ask for clarification on any answers

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16:

When sharing the code, share it as text and not an image

Set a scan_interval: Home-AssistantConfig/sensors/uk_transport.yaml at 9998c1b06f07a1410a9e3dded99eedfdc633688c · DubhAd/Home-AssistantConfig · GitHub

- platform: uk_transport
  app_id: !secret transport_app_id
  app_key: !secret transport_app_key
  # Once a week
  scan_interval: 604800
  queries:
...

and update from an automation:

  - service: homeassistant.update_entity
    target:
      entity_id: sensor.next_train_to_abc

Hi Tinkerer,

Thanks for the quick reply.

Apologies for not sharing as text. I thought it would be a lot easier for me to blank out the locations and other private info in the image.

And as I mentioned, I’m very new to HA and esp new to yaml. I took a look at the link you posted about posting as text etc, but couldn’t work out how to easily get it to format correctly, instead of just a bunch of text. I’m still very much learning.

Thanks for the tip on the scan interval.

Re: the automation, I’ve been searching and trying to work out how homeassistant.update.entity works, but can’t get my head around it. How do I use that to trigger an update?

Sorry if these seem obvious and simple, but I’m still getting my head around this, and when I searched the HA documents for it, I couldn’t figure it out.

As easy as it shows:

```yaml
your: yaml_here
```

Becomes:

your: yaml_here

Calling that action is how you trigger an update of the entity listed. My automation (triggered by the person arriving at the zone around the station) calls that action, which results in the sensor updating.