Button-Card Issue using entities

Hi guys, I have a problem with the button card and I hope you can help me. Here is the very simple code that is giving me some trouble.

type: custom:button-card
entity: sensor.ir_studio
icon: mdi:raspberry-pi
aspect_ratio: 1/1
name: IR Studio
styles:
  card:
    - border-radius: 10%
    - padding: 10%
    - color: ivory
    - font-size: 10px
    - text-shadow: 0px 0px 5px black
    - text-transform: capitalize
  grid:
    - grid-template-areas: '"i esc" "n n" "status status"'
    - grid-template-columns: 1fr 1fr
    - grid-template-rows: 1fr min-content min-content
  name:
    - font-weight: bold
    - font-size: 13px
    - color: white
    - align-self: middle
    - justify-self: start
    - padding-bottom: 4px
  img_cell:
    - justify-content: start
    - align-items: start
    - margin: none
  custom_fields:
    esc:
      - align-self: start
      - justify-self: end
    status:
      - padding-bottom: 2px
      - align-self: middle
      - justify-self: start
      - '--text-color-sensor': '[[[ if (states["sensor.raspbcpu"].state < 80) return "red"; ]]]'
custom_fields:
  esc: |
    [[[
      return `<span>${sensor.ir_studio}</span>`
    ]]]
  status: |
    [[[
      return `<span></span>`
    ]]]

and this is the error on the screen

uttonCardJSTemplateError: ReferenceError: sensor is not defined in 'return `<span>${sensor.ir_studio}</span>`'

sensor.ir_studio is an entity present in the system that works well.
Any ideas?

Try

      return `<span>${states["sensor.ir_studio"].state}</span>`

Great!!! It works.
Thanks a lot.

I take this opportunity for another question.
The sensor states["sensor.ir_studio"].state can assume the values ​​0,1, 2 and 3 which I should translate into Open, Closed, Active and Alarm.
It’s clear to me that I have to introduce an IF THEN ELSE statement but I don’t have a clear syntax.
Could you help me on this too?

I tried to introduce such a change, but it doesn’t work

`<script> function status(s){if(s==0) return "Open";}</script>
 <span>status(${states["sensor.ir_studio"].state})</span>`

In HASS in the sensor status I see Status (0).
It’s like it doesn’t solve the function.
Thanks in advance.