Skip to content

Commit

Permalink
add swing mode and fan mode (#3)
Browse files Browse the repository at this point in the history
* add swing mode and fan mode

* add documentation

* fix combine mode
  • Loading branch information
piitaya authored Apr 26, 2021
1 parent 364b153 commit ada6793
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 31 deletions.
93 changes: 65 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ resources:
## Options
| Name | Type | Required | Description
| :---- | :---- | :---- | :----
| type | string | Yes | `custom:climate-mode-entity-row`
| entity | string | Yes | `domain.my_entity_id`
| name | string | No | Override entity `friendly_name`
| icon | string | No | Override entity `icon`
| | | |
| modes | object | Yes | Modes (see below)
| Name | Type | Required | Description |
| :----- | :----- | :------- | :------------------------------- |
| type | string | Yes | `custom:climate-mode-entity-row` |
| entity | string | Yes | `domain.my_entity_id` |
| name | string | No | Override entity `friendly_name` |
| icon | string | No | Override entity `icon` |
| | | |
| modes | object | Yes | Modes (see below) |

### Mode objects

| Name | Type | Required | Description
:---- | :---- | :---- | :----
| icon | string | No | A icon for the mode
| hvac_mode | string | No | A valid hvac_mode for the entity
| preset_mode | string | No | A valid preset_mode for the entity
| color | string | No | Custom color for the icon when toggle
| Name | Type | Required | Description |
| :---------- | :----- | :------- | :------------------------------------ |
| icon | string | No | A icon for the mode |
| hvac_mode | string | No | A valid hvac_mode for the entity |
| preset_mode | string | No | A valid preset_mode for the entity |
| fan_mode | string | No | A valid fan_mode for the entity |
| swing_mode | string | No | A valid swing_mode for the entity |
| color | string | No | Custom color for the icon when toggle |

## Example

Expand All @@ -53,16 +55,16 @@ resources:
type: entities
entities:
- entity: climate.thermostat_kitchen
type: 'custom:climate-mode-entity-row'
type: "custom:climate-mode-entity-row"
modes:
- hvac_mode: 'off'
- preset_mode: eco
- preset_mode: comfort
- hvac_mode: "off"
- preset_mode: "eco"
- preset_mode: "comfort"
```

### Custom config

![Simple example](images/custom_example.png)
![Custom example](images/custom_example.png)

```yaml
type: entities
Expand All @@ -72,14 +74,49 @@ entities:
name: My Thermostat
icon: 'mdi:home'
modes:
- hvac_mode: 'off'
icon: 'mdi:snowflake'
color: '#B3E5FC'
- preset_mode: eco
icon: 'mdi:moon-waxing-crescent'
color: '#9575CD'
- icon: 'mdi:weather-sunny'
preset_mode: comfort
color: '#FFC107'
- hvac_mode: "off"
icon: "mdi:snowflake"
color: "#B3E5FC"
- preset_mode: "eco"
icon: "mdi:moon-waxing-crescent"
color: "#9575CD"
- preset_mode: "comfort"
icon: "mdi:weather-sunny"
color: "#FFC107"
```

### Multi mode config

You can combine or mix hvac_mode, preset_mode, fan_mode and swing_mode to build your custom controls.

![Multi example](images/multi_example.png)

```yaml
type: entities
entities:
- entity: climate.thermostat_kitchen
type: "custom:climate-mode-entity-row"
name: My Thermostat
icon: "mdi:home"
modes:
- icon: "mdi:brightness-auto"
hvac_mode: "heat"
fan_mode: "on_high"
swing_mode: "auto"
color: "#34c6eb"
- hvac_mode: "off"
icon: "mdi:snowflake"
color: "#B3E5FC"
- hvac_mode: "heat"
icon: "mdi:fire"
color: "#FFC107"
- fan_mode: "off"
swing_mode: "off"
icon: "mdi:fan-off"
color: "#FF6659"
- fan_mode: "on_high"
swing_mode: "auto"
icon: "mdi:fan"
color: "#76D275"
```
25 changes: 22 additions & 3 deletions climate-mode-entity-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@

renderMode(mode) {
const isActive =
((!mode.preset_mode || mode.preset_mode === this.state.preset_mode) &&
!mode.hvac_mode) ||
mode.hvac_mode === this.state.hvac_mode;
(!mode.preset_mode || mode.preset_mode === this.state.preset_mode) &&
(!mode.hvac_mode || mode.hvac_mode === this.state.hvac_mode) &&
(!mode.fan_mode || mode.fan_mode === this.state.fan_mode) &&
(!mode.swing_mode || mode.swing_mode === this.state.swing_mode);

const onClick = () => this.setMode(mode);

Expand Down Expand Up @@ -99,6 +100,20 @@
preset_mode: mode.preset_mode,
});
}

if (mode.fan_mode) {
this._hass.callService("climate", "set_fan_mode", {
entity_id: this._config.entity,
fan_mode: mode.fan_mode,
});
}

if (mode.swing_mode) {
this._hass.callService("climate", "set_swing_mode", {
entity_id: this._config.entity,
swing_mode: mode.swing_mode,
});
}
}

setConfig(config) {
Expand All @@ -115,11 +130,15 @@

const hvac_mode = entity.state;
const preset_mode = entity.attributes.preset_mode;
const fan_mode = entity.attributes.fan_mode;
const swing_mode = entity.attributes.swing_mode;

this.state = {
entity,
hvac_mode,
preset_mode,
fan_mode,
swing_mode,
};
}
}
Expand Down
Binary file added images/multi_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ada6793

Please sign in to comment.