---
title: "Colours"
description: "TapHome script colours: convert hue, saturation and brightness to RGB with HSVTORGB and back with RGBTOHSV, and control RGB lights from scripts."
url: "https://taphome.com/en/docs/script/colours/"
language: en
lastmod: 2026-10-13
generator: hugo
ai:
  topics: ["color-conversion","rgb-light","scripting-language"]
  questions: ["How do I convert HSV colour to RGB in a TapHome script?","How do I convert RGB colour to HSV in a TapHome script?","How do I control an RGB light from a Packet parser script?","What range do hue, saturation and value have in TapHome scripts?","What properties do rgbcolor and hsvcolor values have?"]
---

# Colours

TapHome script colour functions — HSVTORGB and RGBTOHSV — and the rgbcolor and hsvcolor value types used to control RGB lights from Packet parser and Modbus scripts.

Last updated: 2026-10-13

Colour functions convert between the HSV model — hue, saturation and value (brightness) — and the RGB model of red, green and blue channels. A TapHome colour light works with hue and saturation; many devices driven from [Packet parser](https://taphome.com/en/docs/script/packet-parser/) or [Modbus](https://taphome.com/en/docs/script/modbus/) scripts expect red, green and blue instead. Both functions work in every script and need Core 2023.1 or newer.

## HSVTORGB

`HSVTORGB` converts a colour given by hue, saturation and value into an `rgbcolor` value with red, green and blue channels from 0 to 255.

```text
HSVTORGB(hue, saturation, value)
```

| Name | Type | Description |
|---|---|---|
| `hue` | number | Colour angle in degrees, 0 – 360 (0 red, 120 green, 240 blue). |
| `saturation` | number | 0 – 1. 0 is white or grey, 1 the full colour. |
| `value` | number | Brightness, 0 – 1. |

**Returns** — `rgbcolor` with the properties `RED`, `GREEN` and `BLUE`, each rounded to a whole number 0 – 255.

**Remarks** — The inputs are not limited to their range. Keep `saturation` and `value` between 0 and 1, otherwise the channels overflow the 0 – 255 range.

**Example**

```taphome
VAR green := HSVTORGB(120, 1, 1);
green.GREEN;
# Result: 255
```

**Example — write script of an RGB light over HTTP**

In the write script of a colour light, pass the light's hue (`Hd`) and saturation (`Sa`) values and keep the brightness separate. Here they are local variables so the example runs on its own:

```taphome
# hue and saturation of the light
VAR hue := 30;
VAR saturation := 1;
# convert to red, green and blue
VAR color := HSVTORGB(hue, saturation, 1);
# build the request body
"red=" + color.RED + "&green=" + color.GREEN + "&blue=" + color.BLUE;
# Result: "red=255&green=128&blue=0"
```

**See also** — [RGBTOHSV](https://taphome.com/en/docs/script/colours/#rgbtohsv), [SENDHTTPREQUEST](https://taphome.com/en/docs/script/packet-parser/#sendhttprequest).

## RGBTOHSV

`RGBTOHSV` converts red, green and blue channels (0 – 255) into an `hsvcolor` value with hue in degrees and saturation and value from 0 to 1.

```text
RGBTOHSV(red, green, blue)
```

| Name | Type | Description |
|---|---|---|
| `red`, `green`, `blue` | number | 0 – 255. Each is converted to a whole number in that range. |

**Returns** — `hsvcolor` with `HUE` (0 – 360, with a fraction), `SATURATION` (0 – 1) and `VALUE` (0 – 1). For grey colours, where all channels are equal, `HUE` and `SATURATION` are 0.

**Example — read the hue of a light that reports red, green and blue**

```taphome
VAR hsv := RGBTOHSV(255, 128, 0);
ROUND(hsv.HUE);
# Result: 30
```

```taphome
VAR hsv := RGBTOHSV(255, 128, 0);
ROUND(hsv.SATURATION * 100) / 100;
# Result: 1
```

## rgbcolor and hsvcolor values

`rgbcolor` and `hsvcolor` are the value types returned by the colour functions; their properties can be read and written.

| Type | Property | Range | Note |
|---|---|---|---|
| `rgbcolor` | `RED`, `GREEN`, `BLUE` | 0 – 255 | Writing stores a byte: values above 255 wrap around. |
| `hsvcolor` | `HUE` | 0 – 360 | Writing stores a byte, so a hue above 255 wraps around — `hsv.HUE := 300` gives 44. Pass the hue to `HSVTORGB` instead. |
| `hsvcolor` | `SATURATION`, `VALUE` | 0 – 1 | Decimal numbers. |

Both type names can declare a variable:

```taphome
rgbcolor colour := HSVTORGB(240, 1, 0.5);
colour.BLUE;
# Result: 128
```

**See also** — [Data types](https://taphome.com/en/docs/script/data-types/), [Variables and constants](https://taphome.com/en/docs/script/variables/).
