Added "SET" implementation for gauge values
This commit is contained in:
@@ -19,6 +19,7 @@ substitutions:
|
|||||||
gauge0_max: "7300.0"
|
gauge0_max: "7300.0"
|
||||||
gauge0_max_steps: "4000"
|
gauge0_max_steps: "4000"
|
||||||
gauge0_unit: W
|
gauge0_unit: W
|
||||||
|
gauge0_step: "1.0"
|
||||||
gauge0_default_speed: "5000"
|
gauge0_default_speed: "5000"
|
||||||
gauge0_default_accel: "6000"
|
gauge0_default_accel: "6000"
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ substitutions:
|
|||||||
gauge1_max: "7300.0"
|
gauge1_max: "7300.0"
|
||||||
gauge1_max_steps: "4000"
|
gauge1_max_steps: "4000"
|
||||||
gauge1_unit: W
|
gauge1_unit: W
|
||||||
|
gauge1_step: "1.0"
|
||||||
gauge1_default_speed: "5000"
|
gauge1_default_speed: "5000"
|
||||||
gauge1_default_accel: "6000"
|
gauge1_default_accel: "6000"
|
||||||
|
|
||||||
@@ -116,6 +118,22 @@ sensor:
|
|||||||
name: Uptime
|
name: Uptime
|
||||||
entity_category: diagnostic
|
entity_category: diagnostic
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
name: "${gauge0_entity_name} Target"
|
||||||
|
lambda: |-
|
||||||
|
return id(gauge0_target_value);
|
||||||
|
unit_of_measurement: "${gauge0_unit}"
|
||||||
|
accuracy_decimals: 1
|
||||||
|
update_interval: 5s
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
name: "${gauge1_entity_name} Target"
|
||||||
|
lambda: |-
|
||||||
|
return id(gauge1_target_value);
|
||||||
|
unit_of_measurement: "${gauge1_unit}"
|
||||||
|
accuracy_decimals: 1
|
||||||
|
update_interval: 5s
|
||||||
|
|
||||||
text_sensor:
|
text_sensor:
|
||||||
- platform: wifi_info
|
- platform: wifi_info
|
||||||
ip_address:
|
ip_address:
|
||||||
@@ -125,11 +143,78 @@ text_sensor:
|
|||||||
name: SSID
|
name: SSID
|
||||||
entity_category: diagnostic
|
entity_category: diagnostic
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Gauge target numbers
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
number:
|
||||||
|
- platform: template
|
||||||
|
id: gauge0_target_number
|
||||||
|
name: "${gauge0_entity_name}"
|
||||||
|
unit_of_measurement: "${gauge0_unit}"
|
||||||
|
min_value: ${gauge0_min}
|
||||||
|
max_value: ${gauge0_max}
|
||||||
|
step: ${gauge0_step}
|
||||||
|
mode: box
|
||||||
|
optimistic: true
|
||||||
|
restore_value: false
|
||||||
|
initial_value: ${gauge0_min}
|
||||||
|
set_action:
|
||||||
|
- lambda: |-
|
||||||
|
const float min_value = ${gauge0_min};
|
||||||
|
const float max_value = ${gauge0_max};
|
||||||
|
const int max_steps = ${gauge0_max_steps};
|
||||||
|
const float clamped = std::max(min_value, std::min(max_value, x));
|
||||||
|
int steps = 0;
|
||||||
|
if (max_value > min_value) {
|
||||||
|
const float fraction = (clamped - min_value) / (max_value - min_value);
|
||||||
|
steps = static_cast<int>(lroundf(fraction * max_steps));
|
||||||
|
}
|
||||||
|
id(gauge0_target_value) = clamped;
|
||||||
|
char cmd[24];
|
||||||
|
snprintf(cmd, sizeof(cmd), "SET 0 %d\n", steps);
|
||||||
|
id(arduino_uart).write_str(cmd);
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
id: gauge1_target_number
|
||||||
|
name: "${gauge1_entity_name}"
|
||||||
|
unit_of_measurement: "${gauge1_unit}"
|
||||||
|
min_value: ${gauge1_min}
|
||||||
|
max_value: ${gauge1_max}
|
||||||
|
step: ${gauge1_step}
|
||||||
|
mode: box
|
||||||
|
optimistic: true
|
||||||
|
restore_value: false
|
||||||
|
initial_value: ${gauge1_min}
|
||||||
|
set_action:
|
||||||
|
- lambda: |-
|
||||||
|
const float min_value = ${gauge1_min};
|
||||||
|
const float max_value = ${gauge1_max};
|
||||||
|
const int max_steps = ${gauge1_max_steps};
|
||||||
|
const float clamped = std::max(min_value, std::min(max_value, x));
|
||||||
|
int steps = 0;
|
||||||
|
if (max_value > min_value) {
|
||||||
|
const float fraction = (clamped - min_value) / (max_value - min_value);
|
||||||
|
steps = static_cast<int>(lroundf(fraction * max_steps));
|
||||||
|
}
|
||||||
|
id(gauge1_target_value) = clamped;
|
||||||
|
char cmd[24];
|
||||||
|
snprintf(cmd, sizeof(cmd), "SET 1 %d\n", steps);
|
||||||
|
id(arduino_uart).write_str(cmd);
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Gauge light state cache
|
# Gauge light state cache
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
globals:
|
globals:
|
||||||
|
- id: gauge0_target_value
|
||||||
|
type: float
|
||||||
|
restore_value: no
|
||||||
|
initial_value: ${gauge0_min}
|
||||||
|
- id: gauge1_target_value
|
||||||
|
type: float
|
||||||
|
restore_value: no
|
||||||
|
initial_value: ${gauge1_min}
|
||||||
- id: gauge0_bl_r
|
- id: gauge0_bl_r
|
||||||
type: int
|
type: int
|
||||||
restore_value: no
|
restore_value: no
|
||||||
|
|||||||
Reference in New Issue
Block a user