CestLaGalere/mobilealerts

[Feature Request] - Please add t2hi for Power Outage sensor

Opened this issue · 12 comments

Hello,
Is it possible to add and support the t2hi, t2hise, t2hiee, t2his sensors?
This is supported via MA10870.

Thanks!

@shocker2 any update on this ?
Or could you privately (not via comment) provide "details" to which you have these devices connected since we do not have these devices.

Have you tried these sensors in the yaml? Looking at the code the addon should return the data for any other elements not recognised but it is not cast to a specific sensor so the value is returned 'as is'

Sorry missed the update on this one, I'll come back with feedback in few hours.

@petrleocompel the documentation now adds in many other elements (https://mobile-alerts.eu/info/public_server_api_documentation.pdf) - two soutions present themselves immediately, (I am sure there are others)

  1. the user puts in a datatype alongside the type, e.g.
  device_id: xxxxxxxx
  name: Temp Alert Ended
  type: t1hiee
  data_type: bool

this provides most extensibility
2. we add this internally with a table of sensor and data_type - means we need to add items as new sensors are released.
see SensorDataTypes below

however there is no 'generic' boolean Sensor type that I can find - can we create a BinarySensorEntity with not BinarySensorDeviceClass?
so maybe the code stays as it is and we just have a MobileAlertsSensor that returns the value with no type?

I was wondering about something like this: in async_setup_platform:

    await coordinator.async_config_entry_first_refresh()
    sensors = []
    for device in config[CONF_DEVICES]:
        device_type = device[CONF_TYPE]
        if device_type in ["t1", "t2", "t3", "t4"]:
            sensors.append(MobileAlertsTemperatureSensor(coordinator, device))
        elif device_type in ["h", "h1", "h2", "h3", "h4"]:
            sensors.append(MobileAlertsHumiditySensor(coordinator, device))
        elif device_type in ["r"]:
            sensors.append(MobileAlertsRainSensor(coordinator, device))
        elif device_type in ["water"]:
            sensors.append(MobileAlertsWaterSensor(coordinator, device))
        elif device_type in SensorDataTypes:
            data_type = SensorDataTypes[device_type]
            if data_type is int:
                sensors.append(MobileAlertsIntSensor(coordinator, device))
            elif data_type is float:
                sensors.append(MobileAlertsFloatSensor(coordinator, device))
            elif data_type is bool:
                sensors.append(MobileAlertsBoolSensor(coordinator, device))
            else
                sensors.append(MobileAlertsStrSensor(coordinator, device))
        else:
            sensors.append(MobileAlertsSensor(coordinator, device))
    add_entities(sensors)

The data types that I extracted from the documentation:

SensorDataTypes = {
    "rhi": bool,
    "rhis": float,
    "rhist": int,
    "rlo": bool,
    "rlos": float,
    "rlost": int,
    "rb": bool,

    "a1": bool,
    "a2": bool,
    "a3": bool,
    "a4": bool,

    "wsa": bool,
    "wsaactive": bool,
    "wsas": float,
    "wga": bool,
    "wgaactive": bool,
    "wgas": float,
    "wds": int,

    "t1hi": bool,
    "t1hise": bool,
    "t1hiee": bool,
    "t1his": float,
    "t1lo": bool,
    "t1lose": bool,
    "t1loee": bool,
    "t1los": float,

    "t2hi": bool,
    "t2hise": bool,
    "t2hiee": bool,
    "t2his": float,
    "t2lo": bool,
    "t2lose": bool,
    "t2loee": bool,
    "t2los": float,


    "hhi": bool,
    "hhise": bool,
    "hhiee": bool,
    "hhis": int,
    "hlo": bool,
    "hlose": bool,
    "hloee": bool,
    "hlos": int,

    "h2hi": bool,
    "h2hise": bool,
    "h2hiee": bool,
    "h2his": int,
    "h2lo": bool,
    "h2lose": bool,
    "h2loee": bool,
    "h2los": int,

    "apmhi": bool,
    "apmhise": bool,
    "apmhiee": bool,
    "apmhis": int,
    "aplo": bool,
    "aplose": bool,
    "aploee": bool,
    "aplos": int,
    "apcr" :	bool,
    "apcrse" :	bool,
    "apcree" :	bool,
    "apcrdt" :	int,
    "apcrt" :	int,
    "apcf" :	bool,
    "apcfse" :	bool,
    "apcfee" :	bool,
    "apcfdt":	int,
    "apcft":	int,

    "ppmhi": bool,
    "ppmhise": bool,
    "ppmhiee": bool,
    "ppmhis": int,

    "wo": bool,
    "woa": bool,
    "wc": bool,
    "wca": bool,
    "wot": bool,
    "wota": bool,
    "wots": float,
    "wct": bool,
    "wcta": bool,
    "wcts": float,

    "wsa": bool,
    "wsaactive": bool,
    "wsas": float,
    "wga": bool,
    "wgaactive": bool,
    "wgas": float,
    "wds": int,

    "h3havghi": bool,
    "h3havghise": bool,
    "h3havghiee": bool,
    "h3havghis": int,

    "h3havglo": bool,
    "h3havglose": bool,
    "h3havgloee": bool,
    "h3havglos": int,
    "h3havgnsm": bool,
    "h3havgt": int,
    "h3havgtactive": bool,
    "h3havgr": int,
    "h24havghi": bool,
    "h24havghise": bool,
    "h24havghiee": bool,
    "h24havghis": int,

    "h24havglo": bool,
    "h24havglose": bool,
    "h24havgloee": bool,
    "h24havglos": int,
    "h24havgnsm": bool,
    "h24havgt": int,
    "h24havgtactive": bool,
    "h24havgr": int,
    "h7davghi": bool,
    "h7davghise": bool,
    "h7davghiee": bool,
    "h7davghis": int,

    "h7davglo": bool,
    "h7davglose": bool,
    "h7davgloee": bool,
    "h7davglos": int,
    "h7davgnsm": bool,
    "h7davgt": int,
    "h7davgtactive": bool,
    "h7davgr": int,
    "h30davghi": bool,
    "h30davghise": bool,
    "h30davghiee": bool,
    "h30davghis": int,

    "h30davglo": bool,
    "h30davglose": bool,
    "h30davgloee": bool,
    "h30davglos": int,
    "h30davgnsm": bool,
    "h30davgt": int,
    "h30davgtactive": bool,
    "h30davgr": int,

    "kp1t": int,
    "kp1c": int,
    "kp2t": int,
    "kp2c": int,
    "kp3t": int,
    "kp3c": int,
    "kp4t": int,
    "kp4c": int,
    "sc": bool,
    "ap": float
}

@shocker2
try:

  device_id: xxxxxxxx
  name: Temp Alert Ended
  type: t1hiee

does this work?

@CestLaGalere as a User I am not big fan of such "universal" solution. Often it has some price.
As developer of course .. this is a way.

I can try to find out the possibilities. But in the end these mappings have definitive number of solutions.

I guess we can add such thing and anybody could just start using whatever sensor even if it is not fully supported yet as class.

You can take a look one of other issues (about wind direction, we might even should add weatherEntity support)

It is kinda a shame that I still have not seen support for scanning or getting your account sensors... To set up everything automatically...

Anyway... in general yes, let's do it.

Some thoughts:

  • HA is moving a lot away from yaml configurations towards GUI
  • Why somebody wants to have Temperature alarm END set up in external system? Why not to use HA + Automations?
  • What entities should we really implement?

If we leave the code as-is they will get a MobileAlertsSensor (see response to shocker2 above) which will just return the state which seems the easiest way - otherwise we need to work out the type of all of these different sensors! I agree that many of these are much better managed within HA - the alerts / levels are set up from the phone and managed withn the MobileAlerts cloud.
I've moved away from these to building my own with ESPHome and Dallas or other sensors - I have a full weather station with the individual bits from aliexpress and an ESP32 which does rainfall,wind spped & dirn, temp, humidity, pressure for much less than the mobilealerts ones - admittedly it needs a tiny amount of solder, but the rest is in yaml so same effort.

This is the OFF state (no power):

{
  "devices": [
    {
      "deviceid": "XXXX",
      "lastseen": 1710879329,
      "measurement": {
        "idx": 1741054,
        "ts": 1710879326,
        "t1": 65295.0,
        "t2": 1.0
      }
    }
  ],
  "success": true

This is the ON state (with power):

{
  "devices": [
    {
      "deviceid": "YYY",
      "lastseen": 1712770736,
      "measurement": {
        "idx": 3348489,
        "ts": 1712770730,
        "t1": 26.7,
        "t2": 0.0
      }
    }
  ],
  "success": true

To not create confusion, there are different devices:
device XXX (power off): is Generator
device YYY (power on): is Power Home
mobilex

@shocker2 try:

  device_id: xxxxxxxx
  name: Temp Alert Ended
  type: t1hiee

does this work?

I'm getting this data:
t1hiee
brave_WGT1sCXISQ

t1hise
image

ON/OFF is inverted in the label as I'm doing a different monitoring. But according to the docs:
t1hise: If the alert condition started because of this measurement.
t1hiee: If an alert condition ended because of this measurement.

@CestLaGalere I never owned any device. I am working on this just out of passion and helping my friend who has some of their products. I normally would recommend "local" devices and ESPHome is my most used devices.

Anyway @shocker2 It seems that it does not recognise data source to get it. I will take a look on this. I will try this on some simpler sensor. After debug I will post result.