RESTful sensor failure behaviour

Hi,

I have a RESTful sensor to read data from luno.com to get the latest Bitcoin value. The problem is, every now and then there’s a glitch and it fails to read the value. The default behavior is that it falls to 0 whereas I’d like to keep the previous value.

This is my sensor code:

  - platform: rest
    name: Luno Bitcoin in Rand
    resource: https://api.mybitx.com/api/1/ticker?pair=XBTZAR
    json_attributes:
      - last_trade 
      - timestamp
      - bid
      - ask
    value_template: '{{ value_json.last_trade }}' 
    unit_of_measurement: "ZAR"

Is there any way I can keep the value at the previous rather than fall to zero if it fails?

I’ve seen that behaviour and there is currently no caching functionality built in to the rest sensor. Sounds like a reasonable feature though. You probably want to display somewhere when the data was last fetched successfully, or maybe an icon that indicates that the data is not current anymore.

Is it possible to use another sensor (like a template) to read the restful data sensor, ignore the obviously wrong values and fall back to the previous value?

I just provided a solution to a similar problem in this post. Let me know if you’d like help converting it to your situation.